2026-01-25 11:00:40 +11:00
|
|
|
import {ListProcessors} from "../../wailsjs/go/main/App";
|
|
|
|
|
|
2025-09-06 10:26:50 +10:00
|
|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
|
|
2025-09-06 11:26:54 +10:00
|
|
|
import { textProcessor } from "../services.js";
|
|
|
|
|
|
|
|
|
|
export class CommandsController extends Controller {
|
2025-09-06 10:26:50 +10:00
|
|
|
static targets = [
|
|
|
|
|
"commandInput",
|
|
|
|
|
"commandSelect",
|
|
|
|
|
];
|
|
|
|
|
|
2026-01-25 11:00:40 +11:00
|
|
|
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);
|
|
|
|
|
});
|
2025-09-06 10:26:50 +10:00
|
|
|
this._options = Array.from(this.commandSelectTarget.options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showCommands(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
this.element.showModal();
|
|
|
|
|
|
|
|
|
|
this.commandInputTarget.setSelectionRange(0, this.commandInputTarget.value.length, "forward");
|
|
|
|
|
this.commandInputTarget.focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleKeyup(ev) {
|
|
|
|
|
this._filterOptions(this.commandInputTarget.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dismissDialog(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
this.element.close();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-25 11:00:40 +11:00
|
|
|
focusSelect(ev) {
|
|
|
|
|
this.commandSelectTarget.focus();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-06 10:26:50 +10:00
|
|
|
runCommand(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
2025-09-06 11:26:54 +10:00
|
|
|
textProcessor.runTextCommand(this.commandSelectTarget.value);
|
2026-01-25 11:00:40 +11:00
|
|
|
this._lastCommand = this.commandSelectTarget.value;
|
|
|
|
|
|
2025-09-06 10:26:50 +10:00
|
|
|
this.element.close();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-25 11:00:40 +11:00
|
|
|
rerunLastCommand(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (this._lastCommand === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textProcessor.runTextCommand(this._lastCommand);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-06 10:26:50 +10:00
|
|
|
_filterOptions(filterText) {
|
|
|
|
|
let inputText = filterText.toLowerCase();
|
|
|
|
|
|
|
|
|
|
let visibleOptions = [];
|
|
|
|
|
for (let opt of this._options) {
|
|
|
|
|
if ((inputText === "") || (opt.innerText.toLowerCase().includes(inputText))) {
|
|
|
|
|
visibleOptions.push(opt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.commandSelectTarget.replaceChildren(...visibleOptions);
|
|
|
|
|
if (visibleOptions.length > 0) {
|
|
|
|
|
this.commandSelectTarget.selectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-06 11:26:54 +10:00
|
|
|
}
|