mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
feat(editor): Improve UX for brace completion from selection (#5024)
⚡ Improve UX for brace completion from selection
This commit is contained in:
@@ -39,15 +39,32 @@ export default mixins(expressionManager, workflowHelpers).extend({
|
||||
},
|
||||
watch: {
|
||||
value(newValue) {
|
||||
const payload: Record<string, unknown> = {
|
||||
changes: {
|
||||
from: 0,
|
||||
to: this.editor?.state.doc.length,
|
||||
insert: newValue,
|
||||
},
|
||||
selection: { anchor: this.cursorPosition, head: this.cursorPosition },
|
||||
};
|
||||
|
||||
/**
|
||||
* If completion from selection, preserve selection.
|
||||
*/
|
||||
if (this.editor) {
|
||||
const [range] = this.editor.state.selection.ranges;
|
||||
|
||||
const isBraceAutoinsertion =
|
||||
this.editor.state.sliceDoc(range.from - 1, range.from) === '{' &&
|
||||
this.editor.state.sliceDoc(range.to, range.to + 1) === '}';
|
||||
|
||||
if (isBraceAutoinsertion) {
|
||||
payload.selection = { anchor: range.from, head: range.to };
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.editor?.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: this.editor.state.doc.length,
|
||||
insert: newValue,
|
||||
},
|
||||
selection: { anchor: this.cursorPosition, head: this.cursorPosition },
|
||||
});
|
||||
this.editor?.dispatch(payload);
|
||||
} catch (_) {
|
||||
// ignore out-of-range selection error on drop
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user