(state: string, channel: Channel)
| 405 | |
| 406 | toHTML(state: string, channel: Channel): HTMLElement { |
| 407 | const div = document.createElement("div"); |
| 408 | div.contentEditable = "false"; |
| 409 | div.classList.add("flexltr", "commandinput"); |
| 410 | this.imprintName(div); |
| 411 | |
| 412 | const label = document.createElement("span"); |
| 413 | label.textContent = this.localizedName + ":"; |
| 414 | |
| 415 | const input = document.createElement("input"); |
| 416 | input.type = "text"; |
| 417 | input.value = state; |
| 418 | input.onkeydown = (e) => { |
| 419 | if (input.selectionStart === 0 && e.key === "Backspace") { |
| 420 | const before = !!div.nextSibling; |
| 421 | const sib = div.nextSibling || div.previousSibling; |
| 422 | div.remove(); |
| 423 | focusElm(sib as HTMLElement, before); |
| 424 | e.preventDefault(); |
| 425 | e.stopImmediatePropagation(); |
| 426 | } |
| 427 | }; |
| 428 | input.onkeyup = (e) => { |
| 429 | if (input.selectionStart === input.value.length && e.key === "ArrowRight") { |
| 430 | focusElm(div, false); |
| 431 | } |
| 432 | const last = this.owner.getState(this, channel); |
| 433 | this.owner.stateChange(this, channel, input.value); |
| 434 | if (this.choices?.length && last !== input.value) { |
| 435 | this.displayChoices(input, channel); |
| 436 | } |
| 437 | }; |
| 438 | |
| 439 | div.append(label, input); |
| 440 | return div; |
| 441 | } |
| 442 | displayChoices(input: HTMLInputElement, channel: Channel) { |
| 443 | const value = input.value; |
| 444 | if (!this.choices) return; |
| 445 | const similar = (str?: string | null) => { |
nothing calls this directly
no test coverage detected