From f5f918087fd2161079117d7922cbd7523150c75a Mon Sep 17 00:00:00 2001 From: Anders Holck Date: Wed, 27 May 2026 11:18:22 +0200 Subject: [PATCH] Fix AI edit: default to insert at cursor, only REPLACE when explicit --- frontend/src/App.vue | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 8ed5c79..0b3119a 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -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.'