From fd6c01067be31e3a4d0aae5457bccba65f6976cc Mon Sep 17 00:00:00 2001 From: marcus Date: Sun, 14 Jun 2026 13:08:02 +0200 Subject: [PATCH] fix(plugin-api): position cursor after insertions and removals in prompt/attachments API Ensure prompt.insertText, attachments.insertFileReference, and attachments.removeFileReference move the cursor to the correct position after modifying the prompt editor. Previously the cursor stayed at the start of inserted text, which broke the natural flow for plugin-driven file attachments like screenshot-paste. --- src/client/src/components/PiWebApp.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/src/components/PiWebApp.ts b/src/client/src/components/PiWebApp.ts index 95493d3..0250799 100644 --- a/src/client/src/components/PiWebApp.ts +++ b/src/client/src/components/PiWebApp.ts @@ -1391,7 +1391,10 @@ export class PiWebApp extends LitElement { if (!editor) return; if (!editor.hasFocus) editor.focus(); const sel = editor.state.selection.main; - editor.dispatch({ changes: { from: sel.from, to: sel.to, insert: text } }); + editor.dispatch({ + changes: { from: sel.from, to: sel.to, insert: text }, + selection: { anchor: sel.from + text.length }, + }); }, getText: () => { return this.promptEditor?.view?.state.doc.toString() ?? ""; @@ -1440,7 +1443,10 @@ export class PiWebApp extends LitElement { const editor = this.promptEditor?.view; if (editor) { const sel = editor.state.selection.main; - editor.dispatch({ changes: { from: sel.from, to: sel.to, insert: reference } }); + editor.dispatch({ + changes: { from: sel.from, to: sel.to, insert: reference }, + selection: { anchor: sel.from + reference.length }, + }); } return reference; }, @@ -1463,6 +1469,7 @@ export class PiWebApp extends LitElement { if (index === -1) return; editor.dispatch({ changes: { from: index, to: index + reference.length, insert: "" }, + selection: { anchor: index }, }); }, };