Skip to content

Put word highlights on the words that changed - #30

Merged
dgsienko merged 2 commits into
dgsienko:mainfrom
bwets:fix/word-highlight-offsets
Nov 20, 2026
Merged

dgsienko merged 2 commits into
dgsienko:mainfrom
bwets:fix/word-highlight-offsets

Conversation

@bwets

@bwets bwets commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Problem

On any indented line, the word-level highlights land to the left of the words that changed, often starting inside the indentation. Every changed line in a typical C#, Python or JS file is affected.

word_diff_ranges rebuilt each word's offset from str.split(), as if the first word started at column 0 and every word was followed by exactly one space. Leading indentation, tabs and runs of spaces were dropped from the count, so with 8 spaces of indentation every mark was shifted 8 characters left.

Fix

_word_spans takes each word's real span with re.finditer(r"\S+"), and the ranges are built from those spans. The matching itself (SequenceMatcher over the words) is unchanged.

Tests

  • test_word_diff_ranges: new cases for leading spaces, a leading tab, runs of spaces between words, and a deleted run of words.
  • test_highlight.py: an end-to-end check that parse_diff_to_json wraps exactly the changed word of an indented line in <mark>.

The new cases fail on main and pass with the fix. pytest (322 passed), ruff check and ruff format --check are clean.

Version bumped to 0.11.3.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xshwvphn2wQmVKLLS2G9kJ

word_diff_ranges rebuilt each word's offset from str.split() as if every
word started at 0 and was followed by exactly one space. Leading
indentation and runs of spaces were dropped, so on any indented line the
marks landed left of the changed words, often inside the indentation.
The ranges now come from the real span of each word in the line.

Bump version to 0.11.3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xshwvphn2wQmVKLLS2G9kJ
The end-to-end test looked for a bare <mark>old</mark>. Matching on
">old</mark>" still proves the mark starts on the changed word, and
keeps passing if the mark gains a class, as dgsienko#31 does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xshwvphn2wQmVKLLS2G9kJ
@bwets
bwets marked this pull request as ready for review November 20, 2026 14:06
@dgsienko
dgsienko merged commit 4d22b8e into dgsienko:main Nov 20, 2026
4 checks passed
@bwets
bwets deleted the fix/word-highlight-offsets branch November 20, 2026 15:37
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.

2 participants