import {ProcessText} from "../wailsjs/go/main/App"; class TextProcessor { setCodeMirrorEditor(editor) { this._editor = editor; window.runtime.EventsOn("process-text-response", (data) => { const changes = data.output.map(span => ({ from: span.pos, to: span.pos + span.len, insert: span.text, })); this._editor.dispatch({ changes: changes }); }); } runTextCommand(command) { if (this._editor === undefined) { return; } let ranges = this._editor.state.selection.ranges; let shouldBeAll = ranges.reduce((a, r) => a && r.from === r.to, true); let inputs = []; if (shouldBeAll) { inputs.push({ text: this._editor.state.doc.toString(), pos: 0, len: this._editor.state.doc.length, }); } else { inputs = ranges.map(r => ({ text: this._editor.state.doc.slice(r.from, r.to).toString(), pos: r.from, len: r.to - r.from, })) } ProcessText({ action: command, input: inputs, }); } } export const textProcessor = new TextProcessor();