4.4 KiB
4.4 KiB
pdftract-2wqir: Keyboard shortcuts verification
Summary
Implemented comprehensive keyboard shortcuts in the inspector frontend for power user productivity.
Changes made
crates/pdftract-cli/src/inspect/frontend/app.js
-
Extended
setupKeyboard()function (lines 443-467 → new):- Added
ArrowUp/ArrowDownhandlers for scrolling within page - Added
?key handler to toggle help overlay - Added
Escapehandler to close help overlay (priority over Escape in inputs) - Improved input handling: Escape now blurs any input/textarea, clears search if in search input
- Added
-
Added
prevPage()andnextPage()wrapper functions (afternavigatePage()):- Semantic wrappers for
navigatePage(-1)andnavigatePage(1) - Matches naming convention suggested in task description
- Semantic wrappers for
-
Added
scrollPage(delta)function:- Scrolls the canvas container by 100px per keypress
- Supports smooth scrolling within long pages
-
Added
toggleHelp(show)function:- Toggles help overlay visibility
- Focuses close button for accessibility when opening
- Hides overlay when
showis false
-
Added
setupHelp()function:- Wires up the ? button click handler
- Wires up close button click handler
- Adds click-outside-to-close behavior
-
Updated
init()function:- Added call to
setupHelp()
- Added call to
crates/pdftract-cli/src/inspect/frontend/index.html
-
Added "?" button in toolbar:
- Placed between search input and layer toggles
aria-label="Show keyboard shortcuts"andtitle="Keyboard shortcuts (?)"- Class
btn-helpfor circular styling
-
Added help overlay at end of body:
- Modal with semi-transparent backdrop
- Lists all keyboard shortcuts with semantic formatting
- Close button (×) in top-right corner
- Click-outside-to-close behavior
crates/pdftract-cli/src/inspect/frontend/style.css
-
Added
.btn-helpstyles:- Circular button (32px × 32px)
- Centered "?" text, weight 600
-
Added
.help-overlaystyles:- Fixed full-screen backdrop (rgba(0,0,0,0.5))
- Flex centering for content
- z-index 2000 (above all other UI)
-
Added
.help-contentstyles:- White rounded card (8px radius)
- Max-width 500px, responsive width
- Box shadow and max-height constraints
-
Added
.help-shortcuts,.help-shortcut,.help-key,.help-descstyles:- Tabular layout for key + description pairs
- Monospace font for keys
- Visual separator between navigation and layer keys
Acceptance criteria verification
| Criteria | Status | Notes |
|---|---|---|
| ArrowLeft on page 5 → goes to page 4 | PASS | navigatePage(-1) called via ArrowLeft handler |
| ArrowRight on last page → no-op | PASS | if(newPage>=0&&newPage<totalPages) check prevents out-of-bounds |
| / focuses search | PASS | Already implemented, confirmed working |
| 1-8 toggle overlays with visual feedback | PASS | toggleLayer() called; layer button active class toggles via applyLayers() |
| Esc blurs input + clears focus | PASS | document.activeElement.blur() on Escape; help overlay closes on Escape |
| ? shows help overlay | PASS | toggleHelp() shows overlay; lists all shortcuts |
Retrospective
What worked
- The existing
setupKeyboard()function was well-structured and easy to extend - Using
dataset.layersfor layer state management made toggleLayer() straightforward - CSS-only layer visibility via
html[data-layers~="layerName"]selector pattern is clean
What didn't
- Initial
setupKeyboard()checkif(e.target.tagName==='INPUT'&&e.target!==searchInput)returnwas too broad—it prevented Escape from blurring non-search inputs. Fixed by restructuring to handle Escape separately before the early return.
Surprise
- The code already had
setupKeyboard()with most shortcuts implemented (arrows, /, 1-9, Escape). This task was primarily about:- Adding
?for help - Adding
ArrowUp/ArrowDownfor scrolling - Improving Escape handling to close help overlay
- Adding
Reusable pattern
- Help overlay pattern:
toggleHelp(show)with semantic boolean, click-outside-to-close viae.target===overlaycheck, and close button focus for accessibility - Keyboard shortcut pattern: Check
e.target.tagNamefor INPUT/TEXTAREA, special-case Escape for blur, usee.preventDefault()on navigation keys to suppress browser defaults