Merge pull request #15696 from Budibase/fix/automation-js-editor
New automation JS editor fixes.
This commit is contained in:
commit
57d6b5dffe
|
@ -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%;
|
||||||
|
|
Loading…
Reference in New Issue