Skip to content
Open
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ import { setEnableFastDiffTemplate } from '@git-diff-view/core';
setEnableFastDiffTemplate(true);
```

By default the inline ranges are merged with a semantic cleanup, which may
highlight everything between the first and the last change on a line as a
single block. This is especially visible for text without word boundaries
(e.g. CJK text). Disable the cleanup to highlight each change separately:

```ts
import { setEnableDiffSemanticCleanup } from '@git-diff-view/core';

setEnableDiffSemanticCleanup(false);
```

| Default | FastDiff |
|---------|----------|
| ![default](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/main/default.png) | ![fastdiff](https://raw.githubusercontent.com/MrWangJustToDo/git-diff-view/main/enableFastDiffTemplate.png) |
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/parse/change-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ export const resetMaxLengthToIgnoreLineDiff = () => {

export const getMaxLengthToIgnoreLineDiff = () => maxLengthToIgnoreLineDiff;

let enableDiffSemanticCleanup = true;

export const getEnableDiffSemanticCleanup = () => enableDiffSemanticCleanup;

export const setEnableDiffSemanticCleanup = (enable: boolean) => {
enableDiffSemanticCleanup = enable;
};

export const resetEnableDiffSemanticCleanup = () => {
enableDiffSemanticCleanup = true;
};

/** Get the maximum position in the range. */
function rangeMax(range: IRange["range"]): number {
return range.location + range.length;
Expand Down Expand Up @@ -222,7 +234,7 @@ export function diffChanges(addition: DiffLine, deletion: DiffLine): { addRange:
};
}

const diffRange = fastDiff(delString, addString, 0, true);
const diffRange = fastDiff(delString, addString, 0, enableDiffSemanticCleanup);

let aStart = 0;
let bStart = 0;
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/parse/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const getPlainDiffTemplate = ({
}) => {
if (diffLine.plainTemplate && diffLine.plainTemplateMode === "relative") return;

if (diffLine.plainTemplate && diffLine.plainTemplateMode === "fast-diff" && enableFastDiffTemplate) return;

const changes = diffLine.changes;

if (!changes || !changes.hasLineChange || !rawLine) return;
Expand Down Expand Up @@ -149,6 +151,15 @@ export const getSyntaxDiffTemplate = ({
)
return;

if (
diffLine.syntaxTemplate &&
diffLine.syntaxTemplateMode === "fast-diff" &&
diffLine.syntaxTemplateName === diffFile._getHighlighterName() &&
diffFile._getHighlighterType() === "class" &&
enableFastDiffTemplate
)
return;

const changes = diffLine.changes;

if (!changes || !changes.hasLineChange) return;
Expand Down