Skip to content

fix(traffic): keep the keyboard-selected row in view - #111

Merged
fylorn merged 1 commit into
devfrom
fix/traffic-keyboard-scroll
Sep 22, 2026
Merged

fylorn merged 1 commit into
devfrom
fix/traffic-keyboard-scroll

Conversation

@fylorn

@fylorn fylorn commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Arrow keys move the highlight in the traffic table, but the keyboard handler in App.tsx calls preventDefault() to stop the page from scrolling, and nothing scrolls instead. With up to 200 rows, pressing ↓ past the bottom of the visible area takes the highlight off-screen, and ↑ back past the top does the same.

What changes

  • After each ↑/↓ the selected row is scrolled into view with scrollIntoView({ block: "nearest" }): only as far as needed, and not at all when it is already visible. It also runs when the cursor is already at the first or last row, so a key press brings back a row that was scrolled away with the wheel.

  • The row is found by request id (data-row, as the other tables do), not by index, so the grouped view works: there the on-screen order is not the order of rows. A row inside a collapsed session is not in the table; then nothing scrolls.

  • Request rows get scroll-margin-top equal to the height of the pinned header (36px: the 24px sort buttons plus the status cell's py-1.5). Without it, a row moving up stops underneath the header from fix(traffic): keep the table header pinned while the list scrolls #108.

  • Request rows also get a 100vw inline scroll margin. When the table is wider than the window (820px with the sidebar expanded), a row always sticks out of the visible area sideways, and nearest scrolls horizontally for it:

    • Chromium shifts the table by its 20px side padding at either end (scrollLeft 0 → 20, and max → max − 20);
    • WebKit shifts it the same 20px at the left end, and from the far right jumps back to the left (scrollLeft 225 → 20).

    A margin of exactly the 20px padding fixes Chromium and the left end in WebKit, but at the far right WebKit still jumps (225 → 0): it rounds the scroll width up (848.84 → 849), so the row falls 0.16px short of the right edge, counts as partly visible and is aligned to the left. With a margin wider than any viewport, neither engine scrolls sideways for a row (in WebKit, starting at 0, 100 and 225 all stay put), and the margin no longer depends on the padding of the block around the table.

  • ↑/↓ are left alone while the session drawer is open, as they already were for the request drawer (the comment above the handler says drawers stop them). Before, the cursor moved unseen behind the session drawer; with this change the list behind it would also have scrolled, and closing the drawer would have left it somewhere else.

Verification

Measured from the DOM in the isolated preview (mocked IPC, full App on the traffic page, about 200 rows), in Chromium and in the system WKWebView (offscreen, the engine Tauri uses on macOS). A probe presses ↑/↓ and after every press checks that the selected row is fully visible (its top not above the pinned header's bottom, its bottom not below the list's, within half a pixel), that the list scrolled only when the row was not already visible and then to exactly that edge, and that scrollLeft did not change. Flat and grouped (all sessions expanded), 820×560 and 1100×720, light and dark, starting scrolled fully left, partway and fully right. In WebKit every run walks the whole list down and back up from each of the three starting positions.

Before: 30 × ↓ from the top at 1100×720 left the selected row at 1074–1106px in a 682px list that had not scrolled.

After:

Chromium WebKit
presses after which the selected row was not fully visible 0 0
presses that scrolled, but not to the edge 0 0
distance from the edge after scrolling up to 0.11px up to 0.5px
presses that changed scrollLeft 0 0
real keys at 820×560: 20 × ↓, row bottom (list height 522) 521.9 521.5
then 15 × ↑, row top (header bottom at 36) 35.9 36.5

The fractions are rounding: Chromium snaps the scroll offset to device pixels, and WebKit rounds the row's rectangle outward before scrolling, so the row stops up to half a pixel inside the edge. The real keys are CDP key presses in Chromium and NSEvent arrow keys in the WKWebView; they land where the probe's synthetic ones do, so the browser's own arrow-key scrolling stays suppressed.

With the session drawer open, 10 real ↓ presses left the list's scroll position and the cursor unchanged (Chromium). After closing it, ↓ moves and scrolls as above.

pnpm typecheck, pnpm test (208 passed) and pnpm build pass.

Not changed here

In the grouped view the cursor still walks rows (newest first, across all sessions), while each session lists its requests oldest first and collapsed sessions are not rendered. So ↓ can move the highlight up within a session, jump to another session, or land on a row that is not on screen: with the first two sessions collapsed, the first 100 presses highlighted nothing visible. Scrolling now follows whichever row is highlighted; making the traversal follow the on-screen order is a separate change.

🤖 Generated with Claude Code

Arrow keys move the highlight in the traffic table, but the handler
calls preventDefault() to stop the page from scrolling and nothing
scrolls instead, so pressing Down past the bottom of the visible area
took the highlight off-screen, and Up past the top did the same.

- After each Up/Down the selected row is scrolled into view with
  block: "nearest": only as far as needed. It also runs when the
  cursor is already at the first or last row, so a key press brings
  back a row that was scrolled away with the wheel.
- The row is found by request id (data-row), not by index, so the
  grouped view works too. A row inside a collapsed session is not in
  the table; then nothing scrolls.
- Request rows get scroll-margin-top equal to the pinned header
  (36px), so a row moving up stops below the header, not under it.
- Request rows get a 100vw inline scroll margin, so "nearest" never
  scrolls sideways when the table is wider than the window. Without
  it Chromium shifts the table by its 20px padding at either end and
  WebKit jumps from the far right back to the far left; a margin of
  exactly 20px is not enough in WebKit, which rounds the scroll width
  up and leaves the row a fraction of a pixel short at the far right.
- Up/Down are left alone while the session drawer is open, as they
  already were for the request drawer. Otherwise the list behind the
  drawer would now scroll with the cursor.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 8dcbe9c into dev Sep 22, 2026
2 checks passed
@fylorn
fylorn deleted the fix/traffic-keyboard-scroll branch September 22, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant