Skip to content

Commit 8ee4d53

Browse files
committed
Add suppoort for Line by Line.
1 parent 31ca57c commit 8ee4d53

3 files changed

Lines changed: 54 additions & 26 deletions

File tree

src/CodeDiff.vue

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { computed, ref, watch } from 'vue-demi'
33
import { createSplitDiff, createUnifiedDiff } from './utils'
44
import UnifiedViewer from './unified/UnifiedViewer.vue'
55
import SplitViewer from './split/SplitViewer.vue'
6+
import DownArrowIcon from './icons/DownArrowIcon.vue'
7+
import UpArrowIcon from './icons/UpArrowIcon.vue'
68
79
import './style.scss'
810
@@ -78,32 +80,32 @@ const raw = computed(() =>
7880
const diffChange = ref(raw.value)
7981
const isNotChanged = computed(() => diffChange.value.stat.additionsNum === 0 && diffChange.value.stat.deletionsNum === 0)
8082
81-
const currentDiffIndex = ref(-1);
83+
const currentDiffIndex = ref(-1)
8284
83-
const goToNextDiff = () => {
84-
const diffs = document.querySelectorAll('.split-side-right.blob-code-addition');
85+
function goToNextDiff() {
86+
const diffs = document.querySelectorAll('.blob-code-addition')
8587
if (currentDiffIndex.value < diffs.length - 1) {
86-
currentDiffIndex.value++;
87-
updateCurrentDiffHighlight(diffs);
88+
currentDiffIndex.value++
89+
updateCurrentDiffHighlight(diffs)
8890
}
8991
}
9092
91-
const goToPrevDiff = () => {
92-
const diffs = document.querySelectorAll('.split-side-right.blob-code-addition');
93+
function goToPrevDiff() {
94+
const diffs = document.querySelectorAll('.blob-code-addition')
9395
if (currentDiffIndex.value > 0) {
94-
currentDiffIndex.value--;
95-
updateCurrentDiffHighlight(diffs);
96+
currentDiffIndex.value--
97+
updateCurrentDiffHighlight(diffs)
9698
}
9799
}
98100
99-
const updateCurrentDiffHighlight = (diffs: NodeListOf<Element>) => {
100-
diffs.forEach((diff: { classList: { remove: (arg0: string) => any } }) => diff.classList.remove('current-diff'));
101+
function updateCurrentDiffHighlight(diffs: NodeListOf<Element>) {
102+
diffs.forEach((diff: { classList: { remove: (arg0: string) => any } }) => diff.classList.remove('current-diff'))
101103
102-
const currentDiff = diffs[currentDiffIndex.value];
104+
const currentDiff = diffs[currentDiffIndex.value]
103105
104106
if (currentDiff) {
105-
currentDiff.classList.add('current-diff');
106-
currentDiff.scrollIntoView({ behavior: 'smooth', block: 'center' });
107+
currentDiff.classList.add('current-diff')
108+
currentDiff.scrollIntoView({ behavior: 'smooth', block: 'center' })
107109
}
108110
}
109111
@@ -128,6 +130,14 @@ watch(() => props, () => {
128130
<div class="info-left">{{ filename }}</div>
129131
<div class="info-left">{{ newFilename }}</div>
130132
</span>
133+
<span class="diff-commandbar">
134+
<button class="command-item-button" title="Next Change" @click="goToNextDiff">
135+
<DownArrowIcon />
136+
</button>
137+
<button class="command-item-button" title="Previous Change" @click="goToPrevDiff">
138+
<UpArrowIcon />
139+
</button>
140+
</span>
131141
<span v-if="!hideStat" class="diff-stat">
132142
<slot name="stat" :stat="diffChange.stat">
133143
<span class="diff-stat-added">+{{ diffChange.stat.additionsNum }} additions</span>
@@ -141,19 +151,15 @@ watch(() => props, () => {
141151
<span class="info-right">
142152
<span style="margin-left: 20px;">{{ newFilename }}</span>
143153
<span class="diff-commandbar">
144-
<button class="command-item-button" title="Next Change" @click="goToNextDiff">
145-
<svg width="1rem" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
146-
<path d="M383.6,322.7L278.6,423c-5.8,6-13.7,9-22.4,9c-8.7,0-16.5-3-22.4-9L128.4,322.7c-12.5-11.9-12.5-31.3,0-43.2 c12.5-11.9,32.7-11.9,45.2,0l50.4,48.2v-217c0-16.9,14.3-30.6,32-30.6c17.7,0,32,13.7,32,30.6v217l50.4-48.2 c12.5-11.9,32.7-11.9,45.2,0C396.1,291.4,396.1,310.7,383.6,322.7z"/>
147-
</svg>
148-
</button>
149-
<button class="command-item-button" title="Previous Change" @click="goToPrevDiff">
150-
<svg width="1rem" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
151-
<path d="M128.4,189.3L233.4,89c5.8-6,13.7-9,22.4-9c8.7,0,16.5,3,22.4,9l105.4,100.3c12.5,11.9,12.5,31.3,0,43.2 c-12.5,11.9-32.7,11.9-45.2,0L288,184.4v217c0,16.9-14.3,30.6-32,30.6c-17.7,0-32-13.7-32-30.6v-217l-50.4,48.2 c-12.5,11.9-32.7,11.9-45.2,0C115.9,220.6,115.9,201.3,128.4,189.3z"/>
152-
</svg>
153-
</button>
154+
<button class="command-item-button" title="Next Change" @click="goToNextDiff">
155+
<DownArrowIcon />
156+
</button>
157+
<button class="command-item-button" title="Previous Change" @click="goToPrevDiff">
158+
<UpArrowIcon />
159+
</button>
154160
</span>
155-
<span v-if="!hideStat" class="diff-stat">
156-
<slot name="stat" :stat="diffChange.stat">
161+
<span v-if="!hideStat" class="diff-stat">
162+
<slot name="stat" :stat="diffChange.stat">
157163
<span class="diff-stat-added">+{{ diffChange.stat.additionsNum }} additions</span>
158164
<span class="diff-stat-deleted">-{{ diffChange.stat.deletionsNum }} deletions</span>
159165
</slot>

src/icons/DownArrowIcon.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
export default {
3+
name: 'DownArrowIcon',
4+
}
5+
</script>
6+
7+
<template>
8+
<svg width="1rem" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
9+
<path d="M383.6,322.7L278.6,423c-5.8,6-13.7,9-22.4,9c-8.7,0-16.5-3-22.4-9L128.4,322.7c-12.5-11.9-12.5-31.3,0-43.2 c12.5-11.9,32.7-11.9,45.2,0l50.4,48.2v-217c0-16.9,14.3-30.6,32-30.6c17.7,0,32,13.7,32,30.6v217l50.4-48.2 c12.5-11.9,32.7-11.9,45.2,0C396.1,291.4,396.1,310.7,383.6,322.7z" />
10+
</svg>
11+
</template>

src/icons/UpArrowIcon.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
export default {
3+
name: 'DownArrowIcon',
4+
}
5+
</script>
6+
7+
<template>
8+
<svg width="1rem" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
9+
<path d="M128.4,189.3L233.4,89c5.8-6,13.7-9,22.4-9c8.7,0,16.5,3,22.4,9l105.4,100.3c12.5,11.9,12.5,31.3,0,43.2 c-12.5,11.9-32.7,11.9-45.2,0L288,184.4v217c0,16.9-14.3,30.6-32,30.6c-17.7,0-32-13.7-32-30.6v-217l-50.4,48.2 c-12.5,11.9-32.7,11.9-45.2,0C115.9,220.6,115.9,201.3,128.4,189.3z" />
10+
</svg>
11+
</template>

0 commit comments

Comments
 (0)