Initial commit
Have the basic workplace worked out
This commit is contained in:
commit
9f2fa96b92
29 changed files with 1889 additions and 0 deletions
52
frontend/src/controllers/commands_controller.js
Normal file
52
frontend/src/controllers/commands_controller.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [
|
||||
"commandInput",
|
||||
"commandSelect",
|
||||
];
|
||||
|
||||
connect() {
|
||||
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();
|
||||
}
|
||||
|
||||
runCommand(ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
console.log("Do this: " + this.commandSelectTarget.value);
|
||||
this.element.close();
|
||||
}
|
||||
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue