diff --git a/packages/builder/src/components/common/CodeEditor/CodeEditor.svelte b/packages/builder/src/components/common/CodeEditor/CodeEditor.svelte index bc88f0f981..69f9a36850 100644 --- a/packages/builder/src/components/common/CodeEditor/CodeEditor.svelte +++ b/packages/builder/src/components/common/CodeEditor/CodeEditor.svelte @@ -244,6 +244,36 @@ ] } + function handleCompletions( + view: EditorView, + from: number, + to: number, + insert: string + ) { + if (jsBindingWrapping && insert === "$") { + let { text } = view.state.doc.lineAt(from) + + const left = from ? text.substring(0, from) : "" + const right = to ? text.substring(to) : "" + const wrap = !left.includes('$("') || !right.includes('")') + const tr = view.state.update( + { + changes: [{ from, insert: wrap ? '$("")' : "$" }], + selection: { + anchor: from + (wrap ? 3 : 1), + }, + }, + { + scrollIntoView: true, + userEvent: "input.type", + } + ) + view.dispatch(tr) + return true + } + return false + } + // None of this is reactive, but it never has been, so we just assume most // config flags aren't changed at runtime // TODO: work out type for base @@ -262,32 +292,7 @@ : "autocomplete-option", }) ) - complete.push( - EditorView.inputHandler.of((view, from, to, insert) => { - if (jsBindingWrapping && insert === "$") { - let { text } = view.state.doc.lineAt(from) - - const left = from ? text.substring(0, from) : "" - const right = to ? text.substring(to) : "" - const wrap = !left.includes('$("') || !right.includes('")') - const tr = view.state.update( - { - changes: [{ from, insert: wrap ? '$("")' : "$" }], - selection: { - anchor: from + (wrap ? 3 : 1), - }, - }, - { - scrollIntoView: true, - userEvent: "input.type", - } - ) - view.dispatch(tr) - return true - } - return false - }) - ) + complete.push(EditorView.inputHandler.of(handleCompletions)) } // JS only plugins