extradoc: word-atomic in-paragraph diff for readable redlines - #78
Open
cassus wants to merge 1 commit into
Open
Conversation
Diff paragraph bodies at word-token granularity so multi-word edits stay single readable chunks in the Docs Suggestions UI instead of char-level fragment-soup, with a char-level fallback for whitespace-only edits (e.g. "PARTI" -> "PART I") so single-space changes stay minimal. Adds regression tests: a one-word change stays one atomic replace opcode (char-level difflib would fragment "brown"->"red" on a spurious shared 'r'); a whitespace-only change falls back to a minimal char-level insert.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Diff paragraph bodies at word-token granularity instead of character level,
so multi-word edits stay single readable chunks in the Docs Suggestions UI
rather than fragmenting into char-level "insert/delete soup". A char-level
fallback kicks in for whitespace-only edits (e.g.
"PARTI"->"PART I") so asingle inserted/removed space stays a minimal edit rather than replacing the
whole token.
Trade-off / scope
This changes the opcodes produced by
_diff_paragraph_runs, which affects anyconsumer of paragraph-level diffs, not just SUGGEST-mode redlines. The intent
is purely cosmetic (fewer, more meaningful suggestion chunks); it does not
change which characters end up in the final document. Happy to gate it behind a
flag if you'd prefer to keep char-level diffing as the default.
Changes
reconcile_v3/lower.py—_word_diff_opcodes/_tokenize_words; wire_diff_paragraph_runsto use them.tests/reconcile_v3/test_lower.py—TestWordAtomicDiff: a one-word changestays one atomic replace opcode (plain char-level
difflibfragments"brown"->"red"on a spurious shared'r'); a whitespace-only changefalls back to a minimal char-level insert.
Verification