Merge pull request #15696 from Budibase/fix/automation-js-editor

New automation JS editor fixes.
This commit is contained in:
Michael Drury 2025-03-07 15:07:31 +00:00 committed by GitHub
commit 57d6b5dffe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 5 deletions

View File

@ -280,16 +280,15 @@
EditorView.inputHandler.of((view, from, to, insert) => { EditorView.inputHandler.of((view, from, to, insert) => {
if (jsBindingWrapping && insert === "$") { if (jsBindingWrapping && insert === "$") {
let { text } = view.state.doc.lineAt(from) let { text } = view.state.doc.lineAt(from)
const left = from ? text.substring(0, from) : "" const left = from ? text.substring(0, from) : ""
const right = to ? text.substring(to) : "" const right = to ? text.substring(to) : ""
const wrap = !left.includes('$("') || !right.includes('")') const wrap =
(!left.includes('$("') || !right.includes('")')) &&
!(left.includes("`") && right.includes("`"))
const anchor = from + (wrap ? 3 : 1)
const tr = view.state.update( const tr = view.state.update(
{ {
changes: [{ from, insert: wrap ? '$("")' : "$" }], changes: [{ from, insert: wrap ? '$("")' : "$" }],
selection: {
anchor: from + (wrap ? 3 : 1),
},
}, },
{ {
scrollIntoView: true, scrollIntoView: true,
@ -297,6 +296,19 @@
} }
) )
view.dispatch(tr) view.dispatch(tr)
// the selection needs to fired after the dispatch - this seems
// to fix an issue with the cursor not moving when the editor is
// first loaded, the first usage of the editor is not ready
// for the anchor to move as well as perform a change
setTimeout(() => {
view.dispatch(
view.state.update({
selection: {
anchor,
},
})
)
}, 1)
return true return true
} }
return false return false
@ -421,6 +433,7 @@
.code-editor { .code-editor {
font-size: 12px; font-size: 12px;
height: 100%; height: 100%;
cursor: text;
} }
.code-editor :global(.cm-editor) { .code-editor :global(.cm-editor) {
height: 100%; height: 100%;