1import { Controller } from "@hotwired/stimulus" 2 3// Debounced submit into the workspaces list frame. The filtering itself happens 4// on the server, so it searches the whole account rather than the page you 5// happen to be on â the previous DOM-only version was wrong for any account 6// with more workspaces than fit on one page. 7export default class extends Controller { 8 static targets = ["input", "form"] 9 static values = { delay: { type: Number, default: 250 } } 10 11 connect() { 12 this.handleShortcut = this.handleShortcut.bind(this) 13 document.addEventListener("keydown", this.handleShortcut) 14 } 15 16 disconnect() { 17 document.removeEventListener("keydown", this.handleShortcut) 18 clearTimeout(this._timer) 19 } 20 21 // "/" focuses the filter, the way it does in most developer tools â but not 22 // while the visitor is typing somewhere else, and not while a menu or dialog 23 // has taken over the keyboard. 24 handleShortcut(event) { 25 if (event.key !== "/" || event.metaKey || event.ctrlKey || event.altKey) return 26 if (document.querySelector("dialog[open]")) return 27 if (document.querySelector('[data-dropdown-menu-part="content"][data-state="open"]')) return 28 29 const active = document.activeElement 30 if (active && (active.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(active.tagName))) return 31 32 event.preventDefault() 33 this.inputTarget.focus() 34 this.inputTarget.select() 35 } 36 37 submit() { 38 clearTimeout(this._timer) 39 this._timer = setTimeout(() => this.formTarget.requestSubmit(), this.delayValue) 40 } 41 42 clear(event) { 43 event?.preventDefault() 44 if (this.inputTarget.value === "") { 45 this.inputTarget.blur() 46 return 47 } 48 this.inputTarget.value = "" 49 clearTimeout(this._timer) 50 this.formTarget.requestSubmit() 51 } 52 53 teardown() { 54 clearTimeout(this._timer) 55 } 56}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.