| 498 | |
| 499 | class FocusSelector extends Mode { |
| 500 | constructor(hints, visibleInputs, selectedInputIndex) { |
| 501 | super(...arguments); |
| 502 | super.init({ |
| 503 | name: "focus-selector", |
| 504 | exitOnClick: true, |
| 505 | keydown: (event) => { |
| 506 | if (event.key === "Tab") { |
| 507 | hints[selectedInputIndex].classList.remove("internal-vimium-selected-input-hint"); |
| 508 | selectedInputIndex += hints.length + (event.shiftKey ? -1 : 1); |
| 509 | selectedInputIndex %= hints.length; |
| 510 | hints[selectedInputIndex].classList.add("internal-vimium-selected-input-hint"); |
| 511 | DomUtils.simulateSelect(visibleInputs[selectedInputIndex].element); |
| 512 | return this.suppressEvent; |
| 513 | } else if (event.key !== "Shift") { |
| 514 | this.exit(); |
| 515 | // Give the new mode the opportunity to handle the event. |
| 516 | return this.restartBubbling; |
| 517 | } |
| 518 | }, |
| 519 | }); |
| 520 | |
| 521 | const div = DomUtils.createElement("div"); |
| 522 | div.id = "vimiumInputMarkerContainer"; |
| 523 | div.className = "vimium-reset"; |
| 524 | for (const el of hints) { |
| 525 | div.appendChild(el); |
| 526 | } |
| 527 | this.hintContainerEl = div; |
| 528 | document.documentElement.appendChild(div); |
| 529 | |
| 530 | DomUtils.simulateSelect(visibleInputs[selectedInputIndex].element); |
| 531 | if (visibleInputs.length === 1) { |
| 532 | this.exit(); |
| 533 | return; |
| 534 | } else { |
| 535 | hints[selectedInputIndex].classList.add("internal-vimium-selected-input-hint"); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | exit() { |
| 540 | super.exit(); |