╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
359 // exception: arrow up/down on an input unfocuses it and forwards 360 // the event so the TUI can move focus between widgets. 361 if (document.activeElement) { 362 const tag = document.activeElement.tagName; 363 const isArrow = event.key === "ArrowUp" || event.key === "ArrowDown" || 364 event.key === "ArrowLeft" || event.key === "ArrowRight"; 365 // a file picker is an input but behaves like a button: every key 366 // but an arrow is native (enter opens its dialog), and an arrow 367 // navigates away from it 368 if (tag === "INPUT" && document.activeElement.type === "file") { 369 if (!isArrow) return; 370 document.activeElement.blur(); 371 } else if (tag === "INPUT" && document.activeElement.readOnly && 372 ["Enter", "ArrowLeft", "ArrowRight"].includes(event.key)) { 373 event.preventDefault(); 374 if (event.key === "Enter") { 375 document.activeElement.select(); 376 return; 377 } 378 wasmInstance.exports._onKeyDown(event.keyCode); 379 wasmInstance.exports._tick(minRows(), maxCols()); 380 return; 381 } else if (tag === "INPUT" && event.key === "Enter") { 382 // enter in a form's text input never submits it; only the 383 // submit button does. a form with no button submits on enter. 384 // an input outside a form has no submit button, so the TUI 385 // handles its enter instead. 386 const form = document.activeElement.form; 387 if (form && ![...form.elements].some((element) => element.tagName === "BUTTON")) return; 388 event.preventDefault(); 389 if (!document.activeElement.form) { 390 wasmInstance.exports._onKeyDown(event.keyCode); 391 wasmInstance.exports._tick(minRows(), maxCols()); 392 } 393 return; 394 } else if (tag === "INPUT" && !document.activeElement.form && !document.activeElement.readOnly && 395 (event.key === "Tab" && !event.shiftKey || 396 event.key === "ArrowRight" && caretAtEnd(document.activeElement))) { 397 // an input outside a form (a search box) reaches the widgets 398 // beside it: Tab, and ArrowRight once the caret is at the end. 399 // blurred first, so the next key isn't the input's; the tick 400 // refocuses it if the TUI focus stayed. 401 event.preventDefault(); 402 document.activeElement.blur(); 403 wasmInstance.exports._onKeyDown(event.keyCode); 404 wasmInstance.exports._tick(minRows(), maxCols()); 405 return; 406 } else if (tag === "INPUT" && (event.key === "ArrowUp" || event.key === "ArrowDown")) { 407 // up/down moves between widgets; left/right stay in the input 408 document.activeElement.blur(); 409 } else if (tag === "BUTTON" && isArrow) { 410 // arrows navigate away from a focused submit button 411 document.activeElement.blur(); 412 } else if (tag === "INPUT" || tag === "BUTTON" || tag === "TEXTAREA") { 413 // Enter (submit / newline), typing, Tab, and a textarea's 414 // arrows — handled natively by the browser 415 return; 416 } 417 } 418 if ((event.key === "ArrowUp" || event.key === "ArrowDown") && scrollFocusedWidget(event.key === "ArrowDown")) { 419 event.preventDefault(); 420 return; 421 } 422 if ((event.key === "PageUp" || event.key === "PageDown") && pageFocusedScroll(event.key === "PageDown")) { 423 event.preventDefault(); 424 return; 425 } 426 if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { 427 event.preventDefault(); 428 } 429 wasmInstance.exports._onKeyDown(event.keyCode); 430 wasmInstance.exports._tick(minRows(), maxCols()); 431 }); 432 433 // delegated listeners survive cell-layer replacement. the controls 434 // themselves are retained inside #grid. 435 document.addEventListener("input", (event) => { 436 const t = event.target; 437 if (!t || (t.tagName !== "INPUT" && t.tagName !== "TEXTAREA") || !t.dataset.focusId) return; 438 sendTextInputValue(Number(t.dataset.focusId), t.value); 439 }); 440 441 document.addEventListener("focusin", (event) => { 442 const t = event.target; 443 if (!t || !t.dataset || !t.dataset.focusId) return; 444 // sync the wasm focus to wherever the browser moved focus 445 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 446 // keyed controls survive a redraw before click. cell links live in the 447 // replaceable backdrop, so their click handler redraws after activation. 448 if (nodeKey(t)?.startsWith("control:")) wasmInstance.exports._tick(minRows(), maxCols()); 449 }); 450 451 grid.addEventListener("click", (event) => { 452 if (event.target.matches("input[readonly]")) { 453 wasmInstance.exports._tick(minRows(), maxCols()); 454 return; 455 } 456 // a link inside a cell's text opens in a new tab on its own 457 if (event.target.closest("a.cell-link")) return; 458 const span = event.target.closest(".clickable"); 459 if (!span) return; 460 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 461 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 462 // wasm routes the click: an in-page link updates focus and re-renders, 463 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 464 // an in-page link doesn't also trigger a redundant full page load. 465 event.preventDefault(); 466 const focusId = Number(span.dataset.focusId); 467 wasmInstance.exports._onMouseClick(focusId); 468 wasmInstance.exports._tick(minRows(), maxCols()); 469 }); 470 471 let resizeTimer = null; 472 window.addEventListener("resize", () => { 473 clearTimeout(resizeTimer); 474 resizeTimer = setTimeout(() => { 475 wasmInstance.exports._tick(minRows(), maxCols()); 476 }, 100); 477 }); 478 }); 479