From 1c1c5a7812c03a9a119e4a6771b3c52f40593503 Mon Sep 17 00:00:00 2001 From: Gregory Kieffer Date: Fri, 20 Nov 2026 14:56:26 +0100 Subject: [PATCH] Let the changed-word highlight be a background, an underline or off The word marks inside a paired remove/add line were always a filled orange background. A new word_highlight setting (background, underline, off) picks how they look. It is a segmented control under "Changed words" in Settings and a "Cycle changed-word highlight" palette command. The marks now carry class="word-hl", so the styling no longer touches the plain the search dialog uses, and they drop the 1px side padding the generic mark rule adds, which pushed the rest of a marked line off the columns of the other side. 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 | 1 + diffui/server/highlight.py | 2 +- diffui/server/models.py | 1 + diffui/server/state.py | 2 ++ diffui/static/app.js | 8 ++++++-- diffui/static/components/SettingsPanel.js | 13 ++++++++++++- diffui/static/lib/useAppearance.js | 9 ++++++++- diffui/static/lib/useKeyboard.js | 11 +++++++++-- diffui/static/style.css | 17 +++++++++++++++++ pyproject.toml | 2 +- tests/test_highlight.py | 20 ++++++++++++++++---- tests/test_server.py | 2 ++ 13 files changed, 78 insertions(+), 14 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 6c12c3a..8b3608c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -57,7 +57,7 @@ diffui/ - Branch-scoped state: reviewed status, comments and session live in `~/.config/diffui/{repo}/{branch}/`, where `{repo}` and `{branch}` are `_safe_name()` of the repo path and branch. `get_repo_root()` and `_cached_current_branch()` are `lru_cache`'d. `_save_json` writes a temp file and renames it. `_load_json` moves an unparseable file aside to `.corrupt`, so the next save cannot overwrite it. - Worktrees: `get_git_dir()` resolves the real git dir for regular repos and linked worktrees. - Comments: `author_type` is `user` or `agent`. `category` is bug, suggestion, nit or question. `status` is open or resolved. The web UI locks a user's comment for editing once an agent replies (`canEdit` in `CommentDisplay.js`). The server does not enforce that. `agentColor()` hashes the author name, so each agent gets its own color. -- Word-level diff: `pair_diff_lines` pairs consecutive removes and adds, and `word_diff_ranges` uses `difflib.SequenceMatcher` for the changed word spans. +- Word-level diff: `pair_diff_lines` pairs consecutive removes and adds, and `word_diff_ranges` uses `difflib.SequenceMatcher` for the changed word spans. They render as ``, styled by the `word-hl-background`, `word-hl-underline` or `word-hl-off` class `useAppearance` puts on `` from the `word_highlight` setting. - Diff line `index`: `parse_diff_to_json` numbers every line of the diff text, and saved comments anchor on that number. `split_into_hunks` returns the lines before the first `@@` as a pseudo hunk. `parse_diff_to_json` emits neither that hunk nor the `@@` lines, but both still advance `index`. Skipping the count shifts every anchor. `file_note` (from `file_change_note`) is set when the header holds a rename, mode change, new or deleted file, or binary marker. - `html=0` on `/api/diff` and `/api/file` skips Pygments HTML and word highlights. The TUI sends it and highlights `text` itself. - Settings: `SettingsUpdate` in `models.py` limits `editor` to code, cursor, vim or nvim and `agent_cli` to claude, codex, opencode or cursor. A new agent CLI also needs an entry in `_AGENT_CMDS` (`routes_review.py`) and `_INTERACTIVE_CMDS` (`routes_agent_terminal.py`). @@ -172,7 +172,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, word_highlight, 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..f5454ec 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ The header shows the current scope. The browser has the same choices in its view - The blame gutter shows the author and age of each line. - `.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. +- 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. - `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/server/highlight.py b/diffui/server/highlight.py index aa31792..955debd 100644 --- a/diffui/server/highlight.py +++ b/diffui/server/highlight.py @@ -57,7 +57,7 @@ def _apply_word_highlights(code_html: str, ranges: list[tuple[int, int]], code_p end = code_html.index(";", i) + 1 if code_html[i] == "&" else i + 1 should_mark = plain_idx in marked_chars if should_mark != in_highlight: - result.append("" if should_mark else "") + result.append('' if should_mark else "") in_highlight = should_mark result.append(code_html[i:end]) plain_idx += 1 diff --git a/diffui/server/models.py b/diffui/server/models.py index f5850e0..a47f5ba 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 + word_highlight: str | None = Field(default=None, pattern="^(background|underline|off)$") keybindings: dict[str, str] | None = None diff --git a/diffui/server/state.py b/diffui/server/state.py index 15a0fbc..7d74ff1 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.word_highlight: str = saved.get("word_highlight", "background") 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, + "word_highlight": self.word_highlight, "keybindings": self.keybindings, } diff --git a/diffui/static/app.js b/diffui/static/app.js index 89a59f7..1378906 100644 --- a/diffui/static/app.js +++ b/diffui/static/app.js @@ -76,6 +76,7 @@ function App() { const [collapseAll, setCollapseAll] = useState(null); const [fontSize, setFontSize] = useState(13); const [wordWrap, setWordWrap] = useState(false); + const [wordHighlight, setWordHighlight] = useState('background'); const [keybindings, setKeybindings] = useState({}); const [commentsPulse, setCommentsPulse] = useState(false); const diffRef = useRef(null); @@ -189,12 +190,13 @@ function App() { } if (settings.font_size) setFontSize(settings.font_size); if (settings.word_wrap !== undefined) setWordWrap(settings.word_wrap); + if (settings.word_highlight) setWordHighlight(settings.word_highlight); if (settings.keybindings) setKeybindings(settings.keybindings); if (session.activeFile) fetchDiff(session.activeFile); }); }, []); - useAppearance({ themeCss, fontSize, wordWrap }); + useAppearance({ themeCss, fontSize, wordWrap, wordHighlight }); const commentsPulseTimer = useRef(null); const handleLiveEvents = useCallback((events) => { @@ -300,6 +302,7 @@ function App() { const handleSettingsChange = useCallback(async (settings) => { if (settings.font_size !== undefined) setFontSize(settings.font_size); if (settings.word_wrap !== undefined) setWordWrap(settings.word_wrap); + if (settings.word_highlight !== undefined) setWordHighlight(settings.word_highlight); if (settings.keybindings !== undefined) setKeybindings(settings.keybindings); const res = await sendJson('/api/settings', 'PUT', settings); const data = await res.json(); @@ -437,7 +440,7 @@ function App() { }, [reviewedCount, files.length]); const { paletteCommands, handleCommand } = useKeyboard({ - keybindings, fontSize, wordWrap, + keybindings, fontSize, wordWrap, wordHighlight, showCompletionRef, dialogOpenRef, visibleFilesRef, activeFileRef, handleFileSelect, handleToggleReview, handleCopyPath, handleSortByRisk, handleExportSummary, handleCopyGitLabLink, handleNextUnreviewed, navigateComment, scrollToHunk, handleToggleWhitespace, @@ -586,6 +589,7 @@ function App() { onClose=${() => setShowSettings(false)} fontSize=${fontSize} wordWrap=${wordWrap} + wordHighlight=${wordHighlight} keybindings=${keybindings} /> `} diff --git a/diffui/static/components/SettingsPanel.js b/diffui/static/components/SettingsPanel.js index 5fa5a42..88575d8 100644 --- a/diffui/static/components/SettingsPanel.js +++ b/diffui/static/components/SettingsPanel.js @@ -6,6 +6,8 @@ import { kb } from '../lib/keys.js'; const html = htm.bind(h); +const WORD_HIGHLIGHT_OPTIONS = [['background', 'Background'], ['underline', 'Underline'], ['off', 'Off']]; + const EDITORS = [ { value: 'code', label: 'VS Code' }, { value: 'cursor', label: 'Cursor' }, @@ -31,7 +33,7 @@ const REBINDABLE_KEYS = [ { id: 'next-unreviewed', label: 'Next unreviewed' }, ]; -export function SettingsPanel({ onChange, onClose, fontSize, wordWrap, keybindings }) { +export function SettingsPanel({ onChange, onClose, fontSize, wordWrap, wordHighlight, keybindings }) { const [settings, setSettings] = useState(null); const [themes, setThemes] = useState([]); const [showKeybindings, setShowKeybindings] = useState(false); @@ -160,6 +162,15 @@ export function SettingsPanel({ onChange, onClose, fontSize, wordWrap, keybindin + +
+
+ ${WORD_HIGHLIGHT_OPTIONS.map(([value, label]) => html` + + `)} +
+
+