dequoter/frontend/src/services.js

31 lines
829 B
JavaScript
Raw Normal View History

2025-09-06 01:26:54 +00:00
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();