diff --git a/AGENTS.md b/AGENTS.md index 773ed70..6878aff 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -86,6 +86,7 @@ diffui/ - `treeOrder()` in `FileTree.js` gives the file order that prev/next file and next-unreviewed follow. `_order_files` in `routes_diff.py` mirrors it for the TUI. Sort by risk turns the tree into one flat list. - The top bar holds navigation and global actions. `FileHeader` above the active viewer holds the per-file ones (view mode, whitespace, blame, resolve all, Mark reviewed). +- Split scrolling: each `.split-pane` scrolls itself, and `syncScroll` in `SplitDiffViewer.js` copies `scrollLeft` and aligns the top row (`alignedScrollTop`), since comment threads take room on one side only. `echo` holds the position it set on the other pane, so that pane's scroll event is not synced back. - `FullFileViewer` renders a window of lines. Hunk blocks use `content-visibility: auto`. - Context: `contextRef` holds the context every `fetchDiff` sends, `FULL_CONTEXT` while the `show_all_lines` setting is on (the All lines button, `e`), else `contextLines` (More / Less context). `fetchDiff` drops a response whose context is no longer current, so the 3-line fetch at startup cannot overwrite the full one. - `SearchDialog` calls `/api/search` 150ms after the last keystroke and aborts the request it replaces. `handleSearchOpen` in `app.js` scrolls to the line the diff shows nearest to a hit (`nearestNewLine`). A file outside the diff sets `browsing` and opens in `FullFileViewer` with `readOnly`, because the server reports an unchanged file as all added. `browsing` swaps `FileHeader` for a short one, makes `handleToggleReview` return, stops `fetchFiles` from resetting the active file, and keeps `activeFile` out of the session save. It ends when the file joins the diff or another file is picked. @@ -103,6 +104,7 @@ Frontend changes follow these rules: - Fonts: `--font-ui` for chrome (bars, buttons, tree, panels, dialogs, toasts), `--font-mono` for code, line numbers, diff paths and comment code blocks. - Borders: only where they carry structure (the bar bottom edge, the tree/diff divider). Use spacing or a background shift elsewhere. - Animations: 0.15s, only where they mean something. +- Scrollbars: styled once for every element at the top of `style.css`, from `--border` and `--gutter-fg`. Do not add per-component scrollbar rules. - No emoji as UI elements. Use text labels or CSS indicators. - Every async action has a loading state. Every interactive element works. diff --git a/README.md b/README.md index 4db8b6e..6bf4091 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,8 @@ The header shows the current scope. The browser has the same choices in its view - Font size and line wrap are in Settings and the command palette. - Changed words inside a modified line are highlighted with a background, an underline, or not at all. Pick the style under "Changed words" in Settings, or cycle it from the command palette. - `w` or the Whitespace button toggles ignore whitespace. +- Scrollbars take the theme's colors: a thin thumb in the border color that brightens on hover. +- In split view the two sides scroll together, up and down and sideways, and paired lines stay level even when a comment thread sits on one side only. - `e` or the All lines button shows every line of the file in unified and split view, instead of the changes with a few lines of context. It is remembered across files and sessions, and the TUI shares it. More context and Less context step the context when it is off. - `ctrl+click` (`cmd+click` on macOS) a line to open it in VS Code, Cursor, Vim or Neovim. Pick the editor in Settings. diff --git a/diffui/static/components/SplitDiffViewer.js b/diffui/static/components/SplitDiffViewer.js index 1e62ccc..70ef9e3 100644 --- a/diffui/static/components/SplitDiffViewer.js +++ b/diffui/static/components/SplitDiffViewer.js @@ -38,6 +38,35 @@ function splitHunkLines(lines) { return { left, right }; } +// Hunk headers and lines sit at the same index in both panes, but a comment thread +// or comment box takes room on one side only, so equal scrollTops drift apart below +// every thread. The target is scrolled to put the row at the top of the source pane +// at its own top, the same distance into it. While the source scrolls through a thread +// the other side lacks, the target waits at the start of the next row. +const ROWS = ':scope > .split-hunk-header, :scope > .split-line'; + +function lastRowAtOrAbove(rows, y) { + let lo = 0; + let hi = rows.length - 1; + while (lo < hi) { + const mid = (lo + hi + 1) >> 1; + if (rows[mid].offsetTop <= y) lo = mid; + else hi = mid - 1; + } + return lo; +} + +function alignedScrollTop(source, target) { + const sourceRows = source.querySelectorAll(ROWS); + const targetRows = target.querySelectorAll(ROWS); + if (!sourceRows.length || sourceRows.length !== targetRows.length) return source.scrollTop; + const sourceTop = source.scrollTop + sourceRows[0].offsetTop; + const i = lastRowAtOrAbove(sourceRows, sourceTop); + const into = sourceTop - sourceRows[i].offsetTop; + const room = i + 1 < targetRows.length ? targetRows[i + 1].offsetTop - targetRows[i].offsetTop : Infinity; + return targetRows[i].offsetTop - targetRows[0].offsetTop + Math.min(into, room); +} + function SplitLine({ line, side, onRightClick, commentRanges }) { if (!line) return html`
`; @@ -57,17 +86,22 @@ export function SplitDiffViewer({ data, comments, actions, containerRef }) { const [commentingLine, setCommentingLine] = useState(null); const leftRef = useRef(null); const rightRef = useRef(null); - const syncing = useRef(false); + // The position each pane was last scrolled to by syncScroll, so its own scroll + // event is recognised as the echo and not synced back. + const echo = useRef(new Map()); const localContainerRef = useRef(null); const { selMenu, pendingSelection, setPendingSelection, commentFromSelection } = useRangeSelection('.split-code', localContainerRef, '.split-pane'); - const syncScroll = (source, target) => { - if (syncing.current) return; - syncing.current = true; - requestAnimationFrame(() => { - if (target.current) target.current.scrollTop = source.current.scrollTop; - syncing.current = false; - }); + const syncScroll = (sourceRef, targetRef) => { + const source = sourceRef.current; + const target = targetRef.current; + if (!source || !target) return; + const expected = echo.current.get(source); + echo.current.delete(source); + if (expected && expected.top === source.scrollTop && expected.left === source.scrollLeft) return; + target.scrollTop = alignedScrollTop(source, target); + target.scrollLeft = source.scrollLeft; + echo.current.set(target, { top: target.scrollTop, left: target.scrollLeft }); }; const handleRightClick = (line) => { setPendingSelection(null); setCommentingLine(line.index); }; diff --git a/diffui/static/style.css b/diffui/static/style.css index 9d244c0..ed6fdb1 100644 --- a/diffui/static/style.css +++ b/diffui/static/style.css @@ -42,6 +42,39 @@ box-sizing: border-box; } +/* Scrollbars follow the theme: a thin thumb in the border color on a + transparent track, brighter on hover. Firefox and Chromium read the + standard properties; Safari falls back to the ::-webkit rules. */ +* { + scrollbar-width: thin; + scrollbar-color: var(--border) transparent; +} + +*:hover { + scrollbar-color: var(--gutter-fg) transparent; +} + +@supports not (scrollbar-color: auto) { + ::-webkit-scrollbar { + width: 8px; + height: 8px; + } + + ::-webkit-scrollbar-track, + ::-webkit-scrollbar-corner { + background: transparent; + } + + ::-webkit-scrollbar-thumb { + background: var(--border); + border-radius: var(--radius-sm); + } + + ::-webkit-scrollbar-thumb:hover { + background: var(--gutter-fg); + } +} + html, body { height: 100%; background: var(--bg);