diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index d28bf95d..0a722e1d 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -345,6 +345,17 @@ export class StrudelMirror { clear() { this.onStartRepl && document.removeEventListener('start-repl', this.onStartRepl); } + getCursorLocation() { + return this.editor.state.selection.main.head; + } + setCursorLocation(col) { + return this.editor.dispatch({ selection: { anchor: col } }); + } + appendCode(code) { + const cursor = this.getCursorLocation(); + this.setCode(this.code + code); + this.setCursorLocation(cursor); + } } function parseBooleans(value) { diff --git a/website/src/repl/Repl.jsx b/website/src/repl/Repl.jsx index d709d058..aabefcdc 100644 --- a/website/src/repl/Repl.jsx +++ b/website/src/repl/Repl.jsx @@ -114,6 +114,7 @@ export function Repl({ embedded = false }) { }, bgFill: false, }); + window.strudelMirror = editor; // init settings