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.
This commit is contained in:
marcus
2026-06-14 15:03:23 +02:00
parent 27a3b2b5ed
commit fd6c01067b
+9 -2
View File
@@ -1391,7 +1391,10 @@ export class PiWebApp extends LitElement {
if (!editor) return; if (!editor) return;
if (!editor.hasFocus) editor.focus(); if (!editor.hasFocus) editor.focus();
const sel = editor.state.selection.main; 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: () => { getText: () => {
return this.promptEditor?.view?.state.doc.toString() ?? ""; return this.promptEditor?.view?.state.doc.toString() ?? "";
@@ -1440,7 +1443,10 @@ export class PiWebApp extends LitElement {
const editor = this.promptEditor?.view; const editor = this.promptEditor?.view;
if (editor) { if (editor) {
const sel = editor.state.selection.main; 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; return reference;
}, },
@@ -1463,6 +1469,7 @@ export class PiWebApp extends LitElement {
if (index === -1) return; if (index === -1) return;
editor.dispatch({ editor.dispatch({
changes: { from: index, to: index + reference.length, insert: "" }, changes: { from: index, to: index + reference.length, insert: "" },
selection: { anchor: index },
}); });
}, },
}; };