Archived
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:
@@ -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 },
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user