Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -172,7 +174,7 @@ All in `~/.config/diffui/`:

| File | Scope | Format |
| --- | --- | --- |
| `settings.json` | Global | `{theme, editor, user_name, agent_cli, font_size, word_wrap, word_highlight, keybindings}` |
| `settings.json` | Global | `{theme, editor, user_name, agent_cli, font_size, word_wrap, word_highlight, 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}` |
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down Expand Up @@ -208,6 +209,7 @@ 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.
- `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
Expand All @@ -225,6 +227,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 |
Expand All @@ -244,7 +247,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.
Expand Down
1 change: 1 addition & 0 deletions diffui/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SettingsUpdate(BaseModel):
font_size: int | None = Field(default=None, ge=8, le=32)
word_wrap: bool | None = None
word_highlight: str | None = Field(default=None, pattern="^(background|underline|off)$")
show_all_lines: bool | None = None
keybindings: dict[str, str] | None = None


Expand Down
2 changes: 2 additions & 0 deletions diffui/server/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self) -> None:
self.font_size: int = saved.get("font_size", 13)
self.word_wrap: bool = saved.get("word_wrap", False)
self.word_highlight: str = saved.get("word_highlight", "background")
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
Expand Down Expand Up @@ -135,6 +136,7 @@ def settings(self) -> dict:
"font_size": self.font_size,
"word_wrap": self.word_wrap,
"word_highlight": self.word_highlight,
"show_all_lines": self.show_all_lines,
"keybindings": self.keybindings,
}

Expand Down
38 changes: 35 additions & 3 deletions diffui/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -92,8 +96,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([]);
Expand Down Expand Up @@ -146,7 +153,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);
}
}, []);
Expand Down Expand Up @@ -192,6 +199,12 @@ function App() {
if (settings.word_wrap !== undefined) setWordWrap(settings.word_wrap);
if (settings.word_highlight) setWordHighlight(settings.word_highlight);
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);
});
}, []);
Expand Down Expand Up @@ -332,7 +345,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') {
Expand All @@ -341,6 +370,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()]) {
Expand Down Expand Up @@ -444,7 +474,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
});
Expand Down Expand Up @@ -538,6 +568,8 @@ function App() {
onToggleBlame=${() => setShowBlame(v => !v)}
contextLines=${contextLines}
onExpandContext=${handleExpandContext}
showAllLines=${showAllLines}
onToggleAllLines=${handleToggleAllLines}
openCommentCount=${activeFileOpenComments}
onBulkResolve=${() => handleBulkResolve(activeFile)}
onToggleReview=${handleToggleReview}
Expand Down
19 changes: 13 additions & 6 deletions diffui/static/components/FileHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -62,20 +64,25 @@ export function FileHeader({ activeFile, stats, reviewed, diffMode, onDiffModeCh
${previewing ? 'Raw' : previewLabel(activeFile)}
</button>
`}
${diffView && html`
<button class=${'btn' + (showBlame ? ' active' : '')} onClick=${onToggleBlame} title="Toggle git blame annotations">
${showBlame ? 'Hide blame' : 'Blame'}
${contextView && html`
<button class=${'btn' + (showAllLines ? ' active' : '')} onClick=${onToggleAllLines} title=${`${showAllLines ? 'Show only the changes and their context' : 'Show every line of the file'} (${kb(keybindings, 'toggle-all-lines')})`}>
All lines
</button>
${contextLines > 3 && html`
${!showAllLines && contextLines > 3 && html`
<button class="btn" onClick=${() => onExpandContext('collapse')} title="Show fewer context lines around changes">
Less context
</button>
`}
${contextLines < 9999 && html`
${!showAllLines && contextLines < 9999 && html`
<button class="btn" onClick=${() => onExpandContext('expand')} title="Show more context lines around changes">
More context
</button>
`}
`}
${diffView && html`
<button class=${'btn' + (showBlame ? ' active' : '')} onClick=${onToggleBlame} title="Toggle git blame annotations">
${showBlame ? 'Hide blame' : 'Blame'}
</button>
${openCommentCount > 0 && html`
<button class="btn" onClick=${onBulkResolve} title="Resolve all open comments in this file">
Resolve all (${openCommentCount})
Expand Down
1 change: 1 addition & 0 deletions diffui/static/components/SettingsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const REBINDABLE_KEYS = [
{ id: 'export-summary', label: 'Export summary' },
{ id: 'toggle-file-tree', label: 'Toggle explorer' },
{ id: 'next-unreviewed', label: 'Next unreviewed' },
{ id: 'toggle-all-lines', label: 'Show all lines' },
];

export function SettingsPanel({ onChange, onClose, fontSize, wordWrap, wordHighlight, keybindings }) {
Expand Down
1 change: 1 addition & 0 deletions diffui/static/components/ShortcutOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const SHORTCUTS = [
{ id: 'next-unreviewed', action: 'Next unreviewed file' },
{ id: 'sort-risk', action: 'Sort by risk' },
{ keys: 'w', action: 'Toggle ignore whitespace' },
{ id: 'toggle-all-lines', action: 'Show all lines of the file' },
{ id: 'toggle-file-tree', action: 'Toggle explorer' },
{ keys: `${mod}+K`, action: 'Command palette' },
{ keys: '/', action: 'Search files and text' },
Expand Down
1 change: 1 addition & 0 deletions diffui/static/lib/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const DEFAULT_KEYS = {
'export-summary': 'S',
'toggle-file-tree': 'b',
'next-unreviewed': ']',
'toggle-all-lines': 'e',
};

export function kb(keybindings, id) {
Expand Down
8 changes: 6 additions & 2 deletions diffui/static/lib/useKeyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useKeyboard({
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
}) {
Expand Down Expand Up @@ -91,6 +91,8 @@ export function useKeyboard({
scrollToHunk(e.key === 'j' ? 'next' : 'prev');
} else if (e.key === 'w') {
handleToggleWhitespace();
} else if (e.key === kb(keybindings, 'toggle-all-lines')) {
handleToggleAllLines();
} else if (e.key === '/') {
e.preventDefault();
setShowRepoSearch(true);
Expand Down Expand Up @@ -126,6 +128,7 @@ export function useKeyboard({
{ id: 'expand-all-hunks', label: 'Expand all hunks', category: 'Actions' },
{ id: 'collapse-all-hunks', label: 'Collapse all hunks', category: 'Actions' },
{ id: 'toggle-whitespace', label: 'Toggle ignore whitespace', keys: 'w', category: 'Actions' },
{ id: 'toggle-all-lines', label: 'Show all lines of the file', keys: kb(keybindings, 'toggle-all-lines'), category: 'Actions' },
{ id: 'toggle-word-wrap', label: 'Toggle word wrap', category: 'Settings' },
{ id: 'cycle-word-highlight', label: 'Cycle changed-word highlight', category: 'Settings' },
{ id: 'font-size-up', label: 'Increase font size', category: 'Settings' },
Expand Down Expand Up @@ -163,6 +166,7 @@ export function useKeyboard({
case 'expand-all-hunks': handleCollapseAll('expand'); break;
case 'collapse-all-hunks': handleCollapseAll('collapse'); break;
case 'toggle-whitespace': handleToggleWhitespace(); break;
case 'toggle-all-lines': handleToggleAllLines(); break;
case 'toggle-word-wrap': handleSettingsChange({ word_wrap: !wordWrap }); break;
case 'cycle-word-highlight': {
const i = WORD_HIGHLIGHT_STYLES.indexOf(wordHighlight);
Expand All @@ -181,7 +185,7 @@ export function useKeyboard({
case 'prev-hunk': scrollToHunk('prev'); break;
case 'next-hunk': scrollToHunk('next'); break;
}
}, [handleToggleReview, handleFileSelect, handleCopyPath, handleCopyGitLabLink, handleExpandContext, handleCollapseAll, handleToggleWhitespace, handleExportSummary, handleSortByRisk, handleBulkResolve, handleSendToAgent, handleExplain, scrollToHunk, handleSettingsChange, wordWrap, wordHighlight, fontSize]);
}, [handleToggleReview, handleFileSelect, handleCopyPath, handleCopyGitLabLink, handleExpandContext, handleToggleAllLines, handleCollapseAll, handleToggleWhitespace, handleExportSummary, handleSortByRisk, handleBulkResolve, handleSendToAgent, handleExplain, scrollToHunk, handleSettingsChange, wordWrap, wordHighlight, fontSize]);

return { paletteCommands, handleCommand };
}
Loading
Loading