╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
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