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
|
||||
const firstNewline = fullText.indexOf('\n')
|
||||
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') {
|
||||
content.value = content.value.trimEnd() + '\n\n' + editContent
|
||||
if (hint === 'REPLACE') {
|
||||
content.value = editContent
|
||||
} else if (hint === 'PREPEND') {
|
||||
content.value = editContent + '\n\n' + content.value
|
||||
} else if (hint === 'CURSOR' || hint === 'INSERT') {
|
||||
// Insert at cursor position
|
||||
} else if (hint === 'APPEND') {
|
||||
content.value = content.value.trimEnd() + '\n\n' + editContent
|
||||
} else {
|
||||
// Default: insert at cursor position
|
||||
const ta = editor.value
|
||||
const pos = ta ? ta.selectionStart : content.value.length
|
||||
content.value = content.value.substring(0, pos) + editContent + content.value.substring(pos)
|
||||
} else {
|
||||
// REPLACE or unknown — replace entire document
|
||||
content.value = hint === 'REPLACE' ? editContent : fullText
|
||||
content.value = content.value.substring(0, pos) + '\n' + (isHint ? editContent : fullText) + content.value.substring(pos)
|
||||
}
|
||||
isDirty.value = true
|
||||
aiChatResponse.value = 'Document updated.'
|
||||
|
||||
Reference in New Issue
Block a user