Added a store
All checks were successful
Build / build (push) Successful in 1m0s

This commit is contained in:
Leon Mika 2026-01-26 09:31:14 +11:00
parent 1d0d3230c9
commit f96b8a8266
9 changed files with 154 additions and 7 deletions

View file

@ -9,6 +9,7 @@ import {multiCursorKeymap, commandPalette} from "./cmplugins.js";
import {StatusController} from "./controllers/status_controller.js";
import {CommandsController} from "./controllers/commands_controller.js";
import {LogPrint, EventsOn} from "../wailsjs/runtime/runtime";
@ -28,5 +29,6 @@ Stimulus.register("commands", CommandsController);
Stimulus.register("status", StatusController);
textProcessor.setCodeMirrorEditor(view);
textProcessor.loadCurrentBuffer().then(() => textProcessor.startAutoSaver());
view.focus();

View file

@ -1,6 +1,14 @@
import {ProcessText} from "../wailsjs/go/main/App";
import {
ProcessText,
LoadCurrentBuffer,
SaveCurrentBuffer,
} from "../wailsjs/go/main/App";
class TextProcessor {
constructor() {
this._lastAutoSave = undefined;
}
setCodeMirrorEditor(editor) {
this._editor = editor;
window.runtime.EventsOn("process-text-response", (data) => {
@ -23,7 +31,7 @@ class TextProcessor {
});
}
runTextCommand(command) {
async runTextCommand(command) {
if (this._editor === undefined) {
return;
}
@ -46,12 +54,32 @@ class TextProcessor {
}))
}
ProcessText({
await ProcessText({
action: command,
input: inputs,
});
await this.saveBuffer();
}
async loadCurrentBuffer() {
let buffer = await LoadCurrentBuffer();
this._editor.dispatch({ changes: { from: 0, to: this._editor.state.doc.length, insert: buffer } });
this._lastAutoSave = buffer;
}
startAutoSaver() {
setInterval(() => {
this.saveBuffer();
}, 1000);
}
async saveBuffer(force) {
let buffer = this._editor.state.doc.toString();
if (force || (buffer !== this._lastAutoSave)) {
this._lastAutoSave = buffer;
await SaveCurrentBuffer(buffer);
}
}
}
export const textProcessor = new TextProcessor();

View file

@ -4,4 +4,8 @@ import {main} from '../models';
export function ListProcessors():Promise<Array<main.ListProcessorsResponse>>;
export function LoadCurrentBuffer():Promise<string>;
export function ProcessText(arg1:main.ProcessTextRequest):Promise<void>;
export function SaveCurrentBuffer(arg1:string):Promise<void>;

View file

@ -6,6 +6,14 @@ export function ListProcessors() {
return window['go']['main']['App']['ListProcessors']();
}
export function LoadCurrentBuffer() {
return window['go']['main']['App']['LoadCurrentBuffer']();
}
export function ProcessText(arg1) {
return window['go']['main']['App']['ProcessText'](arg1);
}
export function SaveCurrentBuffer(arg1) {
return window['go']['main']['App']['SaveCurrentBuffer'](arg1);
}