From ce7ccfdd2e5eb8dc713a0706226e0dec3268968d Mon Sep 17 00:00:00 2001 From: Gregory Kieffer Date: Fri, 20 Nov 2026 15:09:57 +0100 Subject: [PATCH] Add an All lines toggle that shows every line of the file The diff only showed the changes with a few lines of context, hiding the start of the file and the stretches between hunks. More context and Less context could step up to the whole file, but only in unified view, a few clicks at a time, and the choice reset on reload. A show_all_lines setting now asks git for the whole file as context. In the web UI it is the All lines button in the file header, shown in unified and split view, the e key and a palette command. In the TUI it is e, with "all lines" in the status bar. Both save the setting, so it holds across files and sessions. More and Less context now also show in split view, and stay out of the way while All lines is on. Bump version to 0.12.0 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xshwvphn2wQmVKLLS2G9kJ --- AGENTS.md | 4 ++- README.md | 5 ++- diffui/server/models.py | 1 + diffui/server/state.py | 2 ++ diffui/static/app.js | 38 +++++++++++++++++++-- diffui/static/components/FileHeader.js | 19 +++++++---- diffui/static/components/SettingsPanel.js | 1 + diffui/static/components/ShortcutOverlay.js | 1 + diffui/static/lib/keys.js | 1 + diffui/static/lib/useKeyboard.js | 8 +++-- diffui/tui/app.py | 21 ++++++++++-- diffui/tui/client.py | 8 +++-- diffui/tui/screens.py | 1 + pyproject.toml | 2 +- tests/test_server.py | 1 + tests/test_tui.py | 19 +++++++++++ 16 files changed, 114 insertions(+), 18 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 6c12c3a..cf8da5d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -87,6 +87,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). - `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. - Keep the accessibility basics: `role="treeitem"` on tree items, focus trapping in the settings dialog, `:focus-visible` outlines on buttons, and `+`/`-` prefixes next to the diff colors. @@ -124,6 +125,7 @@ After a change: - Open in browser (`o`) writes `activeFile` to `/api/session`, which the web UI restores on load. - Range comments send what the web UI sends for a selection across lines: `line_index` is the first diff line's `index`, `sel_end_index` the last, `sel_start` 0, `sel_end` the last line's text length, and `selected_text` the lines joined by newlines. Threads anchor under the first line. A single line sends none of the selection fields. - Split view: `build_rows(..., split=True)` uses `split_pairs` to pair a run of removes with the run of adds that follows, as `splitHunkLines` does in `SplitDiffViewer.js`. A split `Row` has `old` and `new` (a context line is both), and `row.line` is the new one when there is one. `DiffView.target` picks the line a comment goes against. `side` is None for the keyboard (new side) and is set by `tab` or the pointer. A range follows one side and sorts its lines by `index`, since paired rows are not in diff order. A resize that crosses `SPLIT_MIN_WIDTH` rebuilds the rows. Long lines are cut at the side's edge, because split has no horizontal scroll. +- All lines: `e` (`action_all_lines`) flips `DiffuiApp.all_lines`, saves it as `show_all_lines` through `update_settings`, and reloads the diff with `FULL_CONTEXT`. `_apply_theme` reads it at startup with the theme. - Find in file is client-side: `Find` matches `code_of(line)` of each row, and `code_segments` draws the spans. The `find_step` and `clear_find` bindings sit before the thread ones, and `check_action` enables them only while matches show, so `n` is next thread otherwise. - `SearchScreen` calls `/api/search` 150ms after the last keystroke. `DiffView.goto_line` moves to the nearest new-side line when the diff does not show the hit's line. - Files outside the diff: a result whose path is not in the view's file list sets `DiffuiApp.browsing`. `_load_diff` takes the file from `/api/file` (its `text` per line, since `html` is for the web UI) and wraps it as one hunk of context lines. `DiffView.readonly` then makes `context` return `readonly`, which matches no `c`, `x` or `v` binding, and turns off hover, gutter presses, range selection and split. `check_action` hides Reviewed and Hunks. `_refresh_files` leaves a browsed file open on file events and stops browsing once the file joins the diff. @@ -172,7 +174,7 @@ All in `~/.config/diffui/`: | File | Scope | Format | | --- | --- | --- | -| `settings.json` | Global | `{theme, editor, user_name, agent_cli, font_size, word_wrap, keybindings}` | +| `settings.json` | Global | `{theme, editor, user_name, agent_cli, font_size, word_wrap, show_all_lines, keybindings}` | | `{repo}/{branch}/reviewed.json` | Per branch | `{"path": mtime}` | | `{repo}/{branch}/comments.json` | Per branch | `{"path": [{...}]}` | | `{repo}/{branch}/session.json` | Per branch | `{activeFile, diffMode, showFileTree, showReviewed, scrollPositions}` | diff --git a/README.md b/README.md index 8d37e88..123264e 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ Inside herdr, `A` pastes the prompt into the workspace's agent pane. Anywhere el | `ctrl+f` | Find in this file | | `n` / `N` | Next / previous find match, while matches are showing | | `\|` | Switch between unified and split diff | +| `e` | Show every line of the file, or only the changes. Shared with the web UI's All lines and remembered | | `tab` | Split view: move between the old and new line of a replaced pair | | `c` or `enter` | Comment on the line or range, or reply to the thread | | `v` | Start a line range at the cursor, then extend it with `up` / `down` | @@ -207,6 +208,7 @@ The header shows the current scope. The browser has the same choices in its view - `.md` files get a rendered preview and images show inline. Markdown is sanitized before rendering, and diagram blocks go to kroki.io. - Font size and line wrap are in Settings and the command palette. - `w` or the Whitespace button toggles ignore whitespace. +- `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. ## Keybindings @@ -224,6 +226,7 @@ The header shows the current scope. The browser has the same choices in its view | `c` | Comment on hovered line | | `b` | Toggle explorer sidebar | | `w` | Toggle ignore whitespace | +| `e` | Toggle all lines | | `s` | Toggle sort by risk | | `S` | Copy review summary | | `y` | Copy file path | @@ -243,7 +246,7 @@ Most shortcuts are ignored while a dialog is open. `r`, `a`, `c`, `y`, `s`, `S`, Review state lives in `~/.config/diffui/`: -- `settings.json` holds theme, editor, agent CLI, display name, font size, line wrap and rebound keys. It is global. +- `settings.json` holds theme, editor, agent CLI, display name, font size, line wrap, all lines and rebound keys. It is global. - `{repo}/{branch}/reviewed.json` holds review status. - `{repo}/{branch}/comments.json` holds comments. - `{repo}/{branch}/session.json` holds UI session state: the active file, diff mode, scroll positions and the explorer and reviewed-file toggles. diff --git a/diffui/server/models.py b/diffui/server/models.py index f5850e0..671f414 100644 --- a/diffui/server/models.py +++ b/diffui/server/models.py @@ -46,6 +46,7 @@ class SettingsUpdate(BaseModel): agent_cli: str | None = Field(default=None, pattern="^(claude|codex|opencode|cursor)$") font_size: int | None = Field(default=None, ge=8, le=32) word_wrap: bool | None = None + show_all_lines: bool | None = None keybindings: dict[str, str] | None = None diff --git a/diffui/server/state.py b/diffui/server/state.py index 15a0fbc..637e809 100644 --- a/diffui/server/state.py +++ b/diffui/server/state.py @@ -61,6 +61,7 @@ def __init__(self) -> None: self.agent_cli: str = saved.get("agent_cli", "claude") self.font_size: int = saved.get("font_size", 13) self.word_wrap: bool = saved.get("word_wrap", False) + self.show_all_lines: bool = saved.get("show_all_lines", False) self.keybindings: dict[str, str] = saved.get("keybindings", {}) self.ignore_patterns: list[str] = [] self.theme_index: int = theme_index @@ -133,6 +134,7 @@ def settings(self) -> dict: "agent_cli": self.agent_cli, "font_size": self.font_size, "word_wrap": self.word_wrap, + "show_all_lines": self.show_all_lines, "keybindings": self.keybindings, } diff --git a/diffui/static/app.js b/diffui/static/app.js index 89a59f7..f09408a 100644 --- a/diffui/static/app.js +++ b/diffui/static/app.js @@ -38,6 +38,9 @@ import { useSessionSave } from './lib/useSessionSave.js'; const html = htm.bind(h); +// Context sent for "All lines": large enough that git shows every line of the file. +const FULL_CONTEXT = 1000000; + function App() { const [repos, setRepos] = useState([]); const [files, setFiles] = useState([]); @@ -65,6 +68,7 @@ function App() { const [fileFilter, setFileFilter] = useState(''); const [diffMode, setDiffMode] = useState('unified'); const [contextLines, setContextLines] = useState(3); + const [showAllLines, setShowAllLines] = useState(false); const [showCompletion, setShowCompletion] = useState(false); const [showCommandPalette, setShowCommandPalette] = useState(false); const [showPreview, setShowPreview] = useState(false); @@ -91,8 +95,11 @@ function App() { commentsRef.current = comments; const viewRef = useRef(view); viewRef.current = view; + const showAllLinesRef = useRef(false); + showAllLinesRef.current = showAllLines; + // The context every diff fetch uses unless it passes its own. const contextRef = useRef(contextLines); - contextRef.current = contextLines; + contextRef.current = showAllLines ? FULL_CONTEXT : contextLines; const branchRef = useRef(branch); branchRef.current = branch; const visibleFilesRef = useRef([]); @@ -145,7 +152,7 @@ function App() { const res = await safeFetch(`/api/diff/${encodeURIComponent(path)}?view=${v}&context=${c}&ignore_whitespace=${ws}`); const data = await res.json(); diffCache.current.set(cacheKey, data); - if (activeFileRef.current === path) { + if (activeFileRef.current === path && c === contextRef.current) { setDiffData(data); } }, []); @@ -190,6 +197,12 @@ function App() { if (settings.font_size) setFontSize(settings.font_size); if (settings.word_wrap !== undefined) setWordWrap(settings.word_wrap); if (settings.keybindings) setKeybindings(settings.keybindings); + if (settings.show_all_lines) { + showAllLinesRef.current = true; + contextRef.current = FULL_CONTEXT; + setShowAllLines(true); + if (activeFileRef.current && !session.activeFile) fetchDiff(activeFileRef.current); + } if (session.activeFile) fetchDiff(session.activeFile); }); }, []); @@ -329,7 +342,23 @@ function App() { } }, [handleFileSelect]); + const handleToggleAllLines = useCallback(() => { + const next = !showAllLinesRef.current; + showAllLinesRef.current = next; + contextRef.current = next ? FULL_CONTEXT : 3; + setShowAllLines(next); + setContextLines(3); + sendJson('/api/settings', 'PUT', { show_all_lines: next }); + const af = activeFileRef.current; + if (af) fetchDiff(af); + showToast(next ? 'Showing all lines' : 'Showing changes with 3 lines of context'); + }, [fetchDiff]); + const handleExpandContext = useCallback((direction = 'expand') => { + if (showAllLinesRef.current) { + showToast('All lines is on'); + return; + } const levels = [3, 10, 50, 9999]; let next; if (direction === 'collapse') { @@ -338,6 +367,7 @@ function App() { next = levels.find(l => l > contextLines) || 9999; } setContextLines(next); + contextRef.current = next; const af = activeFileRef.current; if (af) { for (const key of [...diffCache.current.keys()]) { @@ -441,7 +471,7 @@ function App() { showCompletionRef, dialogOpenRef, visibleFilesRef, activeFileRef, handleFileSelect, handleToggleReview, handleCopyPath, handleSortByRisk, handleExportSummary, handleCopyGitLabLink, handleNextUnreviewed, navigateComment, scrollToHunk, handleToggleWhitespace, - handleExpandContext, handleCollapseAll, handleSettingsChange, handleBulkResolve, handleSendToAgent, handleExplain, + handleExpandContext, handleToggleAllLines, handleCollapseAll, handleSettingsChange, handleBulkResolve, handleSendToAgent, handleExplain, setDiffMode, setFileFilter, setSearchTerm, setShowCommandPalette, setShowCompletion, setShowFileFilter, setShowFileTree, setShowGoToLine, setShowRepoSearch, setShowReviewed, setShowSearch, setShowSettings, setShowShortcuts }); @@ -535,6 +565,8 @@ function App() { onToggleBlame=${() => setShowBlame(v => !v)} contextLines=${contextLines} onExpandContext=${handleExpandContext} + showAllLines=${showAllLines} + onToggleAllLines=${handleToggleAllLines} openCommentCount=${activeFileOpenComments} onBulkResolve=${() => handleBulkResolve(activeFile)} onToggleReview=${handleToggleReview} diff --git a/diffui/static/components/FileHeader.js b/diffui/static/components/FileHeader.js index b04e5f7..45d9e64 100644 --- a/diffui/static/components/FileHeader.js +++ b/diffui/static/components/FileHeader.js @@ -8,11 +8,13 @@ const html = htm.bind(h); const MODES = [['unified', 'Unified'], ['split', 'Split'], ['file', 'File']]; -export function FileHeader({ activeFile, stats, reviewed, diffMode, onDiffModeChange, ignoreWhitespace, onToggleWhitespace, showReviewed, onToggleShowReviewed, showBlame, onToggleBlame, contextLines, onExpandContext, openCommentCount, onBulkResolve, onToggleReview, previewing, browsing, onTogglePreview, keybindings }) { +export function FileHeader({ activeFile, stats, reviewed, diffMode, onDiffModeChange, ignoreWhitespace, onToggleWhitespace, showReviewed, onToggleShowReviewed, showBlame, onToggleBlame, contextLines, onExpandContext, showAllLines, onToggleAllLines, openCommentCount, onBulkResolve, onToggleReview, previewing, browsing, onTogglePreview, keybindings }) { const name = activeFile ? shortName(activeFile) : ''; const dir = activeFile ? activeFile.slice(0, activeFile.length - name.length) : ''; const previewable = activeFile && isPreviewable(activeFile); const diffView = activeFile && diffMode === 'unified' && !previewing; + // Unified and split both show hunks of context; the file view always shows every line. + const contextView = activeFile && diffMode !== 'file' && !previewing; const reviewKey = kb(keybindings, 'toggle-review'); const path = html` @@ -62,20 +64,25 @@ export function FileHeader({ activeFile, stats, reviewed, diffMode, onDiffModeCh ${previewing ? 'Raw' : previewLabel(activeFile)} `} - ${diffView && html` - - ${contextLines > 3 && html` + ${!showAllLines && contextLines > 3 && html` `} - ${contextLines < 9999 && html` + ${!showAllLines && contextLines < 9999 && html` `} + `} + ${diffView && html` + ${openCommentCount > 0 && html`