// Thin wrapper around CodeMirror 6 for editing a device's Lua script. // There's no dedicated @codemirror/lang-lua package (verified against // the npm registry and @codemirror/legacy-modes' source) -- Lua // highlighting comes from the legacy StreamLanguage-based mode instead. import { EditorView, basicSetup } from 'codemirror'; import { StreamLanguage } from '@codemirror/language'; import { lua } from '@codemirror/legacy-modes/mode/lua'; const luaLanguage = StreamLanguage.define(lua); export function createScriptEditor(parent: HTMLElement, initialDoc: string): EditorView { return new EditorView({ parent, doc: initialDoc, extensions: [basicSetup, luaLanguage], }); } export function getEditorText(view: EditorView): string { return view.state.doc.toString(); } export function setEditorText(view: EditorView, text: string): void { view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: text }, }); }