31 lines
829 B
JavaScript
31 lines
829 B
JavaScript
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
ProcessText({
|
||
|
|
action: command,
|
||
|
|
input: [
|
||
|
|
{text: this._editor.state.doc.toString(), pos: 0, len: this._editor.state.doc.length}
|
||
|
|
],
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
export const textProcessor = new TextProcessor();
|