Skip to content

Inline highlight merges multiple small insertions into one block (semantic cleanup), no opt-out #73

Description

@inchei

Problem

When one line contains several small insertions, the inline highlight renders everything between the first and the last change as a single block instead of highlighting each change separately. This is especially visible for text without word boundaries (e.g. CJK text):

old: |原画= 作画:スタジオA、金田B、長崎C
new: |原画= 作画:スタジオA[アA]、金田B[カB]、長崎C[ナC]

Actual: one highlight span [アA]、金田B[カB]、長崎C[ナC].
Expected: three separate spans [アA], [カB], [ナC].

Root cause

diffChanges in packages/core/src/parse/change-range.ts calls fastDiff(delString, addString, 0, true). The hardcoded cleanup=true runs diff-match-patch semantic cleanup, which absorbs small equalities (like the 、 separators) into the surrounding edits.

Repro (node, @git-diff-view/file):

import { diffChanges } from "@git-diff-view/file";
const r = diffChanges({ text: newText } as any, { text: oldText } as any);
console.log(JSON.stringify(r.addRange.range));
// single INSERT "[アA]、金田B[カB]、長崎C[ナC]" instead of three INSERTs

Suggestion

Add an opt-out flag following the existing config convention in the same file (e.g. setEnableDiffSemanticCleanup, default true), and make the prebuilt fast-diff template survive rendering when setEnableFastDiffTemplate(true) is set (currently getPlainDiffTemplate/getSyntaxDiffTemplate always rebuild the single-span template, so the flag has no visible effect).

Happy to send a PR with the above.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions