Skip to content

Commit b17fcad

Browse files
committed
feat: add ignoreMatchingLines prop support for line-by-line mode
1 parent c31345b commit b17fcad

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

README-zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Vue.use(CodeDiff)
124124
| hideHeader | 隐藏头部栏 | boolean | - | false |
125125
| hideStat | 隐藏头部栏中的统计信息 | boolean | - | false |
126126
| theme | 用于切换日间模式/夜间模式 | ThemeType | light , dark | light |
127-
| ignoreMatchingLines | 给出一个模式来忽略匹配行,例如:'(time\|token)'**仅支持 side-by-side** | string | - | |
127+
| ignoreMatchingLines | 给出一个模式来忽略匹配行,例如:'(time\|token)' | string | - | |
128128

129129
## 组件事件
130130

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Not recommended, but the relevant capabilities are retained to facilitate migrat
126126
| hideHeader | Hide header bar | boolean | - | false |
127127
| hideStat | Hide statistical part in the header bar | boolean | - | false |
128128
| theme | Add dark mode | ThemeType | light , dark | light |
129-
| ignoreMatchingLines | Give a pattern to ignore matching lines eg: '(time\|token)' (**Only support side-by-side**) | string | - | undefined |
129+
| ignoreMatchingLines | Give a pattern to ignore matching lines eg: '(time\|token)' | string | - | undefined |
130130

131131
## Events
132132

src/CodeDiff.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface Props {
2121
hideHeader?: boolean
2222
hideStat?: boolean
2323
theme?: 'light' | 'dark'
24-
// Give a pattern to ignore matching lines eg: '(time|token)' (**Only support side-by-side**)
24+
// Give a pattern to ignore matching lines eg: '(time|token)'
2525
ignoreMatchingLines?: string
2626
}
2727
@@ -70,7 +70,7 @@ const newString = computed(() => {
7070
7171
const raw = computed(() =>
7272
isUnifiedViewer.value
73-
? createUnifiedDiff(oldString.value, newString.value, props.language, props.diffStyle, props.context)
73+
? createUnifiedDiff(oldString.value, newString.value, props.language, props.diffStyle, props.context, props.ignoreMatchingLines)
7474
: createSplitDiff(oldString.value, newString.value, props.language, props.diffStyle, props.context, props.ignoreMatchingLines),
7575
)
7676
const diffChange = ref(raw.value)

src/utils.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,10 @@ export function createUnifiedDiff(
361361
language = 'plaintext',
362362
diffStyle = 'word',
363363
context = 10,
364+
ignoreMatchingLines?: string,
364365
): UnifiedViewerChange {
365366
const changes = diffLines(oldString, newString)
367+
const ignoreRegex = ignoreMatchingLines ? new RegExp(ignoreMatchingLines) : undefined
366368

367369
let delNum = 0
368370
let addNum = 0
@@ -372,7 +374,7 @@ export function createUnifiedDiff(
372374
const result: UnifiedViewerChange = {
373375
changes: rawChanges,
374376
collector: [],
375-
stat: calcDiffStat(changes),
377+
stat: calcDiffStat(changes, ignoreRegex),
376378
}
377379

378380
for (let i = 0; i < changes.length; i++) {
@@ -434,7 +436,11 @@ export function createUnifiedDiff(
434436
delNum++
435437

436438
const code = getHighlightCode(language, renderWords(nextLine, curLine, diffStyle))
437-
rawChanges.push({ type: DiffType.DELETE, code, delNum })
439+
rawChanges.push({
440+
type: ignoreRegex?.test(curLine) ? DiffType.EQUAL : DiffType.DELETE,
441+
code,
442+
delNum,
443+
})
438444
}
439445

440446
for (let j = 0; j < nextLines.length; j++) {
@@ -443,7 +449,11 @@ export function createUnifiedDiff(
443449
addNum++
444450

445451
const code = getHighlightCode(language, renderWords(curLine, nextLine, diffStyle))
446-
rawChanges.push({ type: DiffType.ADD, code, addNum })
452+
rawChanges.push({
453+
type: ignoreRegex?.test(nextLine) ? DiffType.EQUAL : DiffType.ADD,
454+
code,
455+
addNum,
456+
})
447457
}
448458

449459
skip = true

0 commit comments

Comments
 (0)