Fix AI edit: default to insert at cursor, only REPLACE when explicit
This commit is contained in:
+10
-9
@@ -1049,20 +1049,21 @@ async function sendAiChat() {
|
|||||||
// Parse location hint from AI response
|
// Parse location hint from AI response
|
||||||
const firstNewline = fullText.indexOf('\n')
|
const firstNewline = fullText.indexOf('\n')
|
||||||
const hint = firstNewline > -1 ? fullText.substring(0, firstNewline).trim().toUpperCase() : ''
|
const hint = firstNewline > -1 ? fullText.substring(0, firstNewline).trim().toUpperCase() : ''
|
||||||
const editContent = firstNewline > -1 ? fullText.substring(firstNewline + 1) : fullText
|
const knownHints = ['APPEND', 'PREPEND', 'CURSOR', 'INSERT', 'REPLACE']
|
||||||
|
const isHint = knownHints.includes(hint)
|
||||||
|
const editContent = isHint ? fullText.substring(firstNewline + 1) : fullText
|
||||||
|
|
||||||
if (hint === 'APPEND') {
|
if (hint === 'REPLACE') {
|
||||||
content.value = content.value.trimEnd() + '\n\n' + editContent
|
content.value = editContent
|
||||||
} else if (hint === 'PREPEND') {
|
} else if (hint === 'PREPEND') {
|
||||||
content.value = editContent + '\n\n' + content.value
|
content.value = editContent + '\n\n' + content.value
|
||||||
} else if (hint === 'CURSOR' || hint === 'INSERT') {
|
} else if (hint === 'APPEND') {
|
||||||
// Insert at cursor position
|
content.value = content.value.trimEnd() + '\n\n' + editContent
|
||||||
|
} else {
|
||||||
|
// Default: insert at cursor position
|
||||||
const ta = editor.value
|
const ta = editor.value
|
||||||
const pos = ta ? ta.selectionStart : content.value.length
|
const pos = ta ? ta.selectionStart : content.value.length
|
||||||
content.value = content.value.substring(0, pos) + editContent + content.value.substring(pos)
|
content.value = content.value.substring(0, pos) + '\n' + (isHint ? editContent : fullText) + content.value.substring(pos)
|
||||||
} else {
|
|
||||||
// REPLACE or unknown — replace entire document
|
|
||||||
content.value = hint === 'REPLACE' ? editContent : fullText
|
|
||||||
}
|
}
|
||||||
isDirty.value = true
|
isDirty.value = true
|
||||||
aiChatResponse.value = 'Document updated.'
|
aiChatResponse.value = 'Document updated.'
|
||||||
|
|||||||
Reference in New Issue
Block a user