Added some more commands and mades some quality of life improvements
All checks were successful
Build / build (push) Successful in 4m27s

This commit is contained in:
Leon Mika 2026-01-25 11:00:40 +11:00
parent 3a23118036
commit 3cb5795ca5
17 changed files with 432 additions and 75 deletions

View file

@ -1,3 +1,26 @@
#app {
display: flex;
flex-direction: column;
}
.editor-mountpoint {
flex-grow: 1;
flex-shrink: 1;
}
.status-bar {
height: 2em;
background-color: rgb(245, 245, 245);
border-top: solid thin rgb(200, 200, 200);
align-content: center;
padding-inline: 8px;
}
.status-bar.deemphasized {
opacity: 0.5;
}
.cm-editor {
height: 100%;
width: 100%;

View file

@ -37,4 +37,12 @@ export const commandPalette = keymap.of([{
return true;
}
}]);
}, {
key: "Cmd-P",
run: () => {
let event = new CustomEvent('dq-rerunlastcommand');
window.dispatchEvent(event);
return true;
}
}]);

View file

@ -1,3 +1,5 @@
import {ListProcessors} from "../../wailsjs/go/main/App";
import { Controller } from "@hotwired/stimulus"
import { textProcessor } from "../services.js";
@ -8,7 +10,16 @@ export class CommandsController extends Controller {
"commandSelect",
];
connect() {
async connect() {
this._lastCommand = null;
let processors = await ListProcessors();
processors.forEach((processor) => {
let option = document.createElement("option");
option.value = processor.name;
option.text = processor.label;
this.commandSelectTarget.appendChild(option);
});
this._options = Array.from(this.commandSelectTarget.options);
}
@ -29,13 +40,29 @@ export class CommandsController extends Controller {
this.element.close();
}
focusSelect(ev) {
this.commandSelectTarget.focus();
}
runCommand(ev) {
ev.preventDefault();
textProcessor.runTextCommand(this.commandSelectTarget.value);
this._lastCommand = this.commandSelectTarget.value;
this.element.close();
}
rerunLastCommand(ev) {
ev.preventDefault();
if (this._lastCommand === null) {
return;
}
textProcessor.runTextCommand(this._lastCommand);
}
_filterOptions(filterText) {
let inputText = filterText.toLowerCase();

View file

@ -0,0 +1,14 @@
import { Controller } from "@hotwired/stimulus"
export class StatusController extends Controller {
connect() {
window.runtime.EventsOn("set-statusbar-message", (data) => {
this._setStatusbarMessage(data.message);
});
}
_setStatusbarMessage(message) {
this.element.textContent = message;
this.element.classList.remove("deemphasized");
}
}

View file

@ -7,11 +7,13 @@ import {Application} from "@hotwired/stimulus";
import {textProcessor} from "./services.js";
import {multiCursorKeymap, commandPalette} from "./cmplugins.js";
import {StatusController} from "./controllers/status_controller.js";
import {CommandsController} from "./controllers/commands_controller.js";
const view = new EditorView({
parent: document.querySelector("#app"),
parent: document.querySelector("#app .editor-mountpoint"),
doc: "",
extensions: [
basicSetup,
@ -23,6 +25,7 @@ const view = new EditorView({
window.Stimulus = Application.start()
Stimulus.register("commands", CommandsController);
Stimulus.register("status", StatusController);
textProcessor.setCodeMirrorEditor(view);

View file

@ -4,11 +4,21 @@ 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,
}));
const changes = data.output.map(span => {
if (span.append) {
return {
from: span.pos + span.len,
to: span.pos + span.len,
insert: span.text,
};
} else {
return {
from: span.pos,
to: span.pos + span.len,
insert: span.text,
};
}
});
this._editor.dispatch({ changes: changes });
});
}