@@ -3,6 +3,8 @@ import { computed, ref, watch } from 'vue-demi'
33import { createSplitDiff , createUnifiedDiff } from ' ./utils'
44import UnifiedViewer from ' ./unified/UnifiedViewer.vue'
55import SplitViewer from ' ./split/SplitViewer.vue'
6+ import DownArrowIcon from ' ./icons/DownArrowIcon.vue'
7+ import UpArrowIcon from ' ./icons/UpArrowIcon.vue'
68
79import ' ./style.scss'
810
@@ -78,6 +80,35 @@ const raw = computed(() =>
7880const diffChange = ref (raw .value )
7981const isNotChanged = computed (() => diffChange .value .stat .additionsNum === 0 && diffChange .value .stat .deletionsNum === 0 )
8082
83+ const currentDiffIndex = ref (- 1 )
84+
85+ function goToNextDiff() {
86+ const diffs = document .querySelectorAll (' .blob-code-addition' )
87+ if (currentDiffIndex .value < diffs .length - 1 ) {
88+ currentDiffIndex .value ++
89+ updateCurrentDiffHighlight (diffs )
90+ }
91+ }
92+
93+ function goToPrevDiff() {
94+ const diffs = document .querySelectorAll (' .blob-code-addition' )
95+ if (currentDiffIndex .value > 0 ) {
96+ currentDiffIndex .value --
97+ updateCurrentDiffHighlight (diffs )
98+ }
99+ }
100+
101+ function updateCurrentDiffHighlight(diffs : NodeListOf <Element >) {
102+ diffs .forEach ((diff : { classList: { remove: (arg0 : string ) => any } }) => diff .classList .remove (' current-diff' ))
103+
104+ const currentDiff = diffs [currentDiffIndex .value ]
105+
106+ if (currentDiff ) {
107+ currentDiff .classList .add (' current-diff' )
108+ currentDiff .scrollIntoView ({ behavior: ' smooth' , block: ' center' })
109+ }
110+ }
111+
81112watch (() => props , () => {
82113 diffChange .value = raw .value
83114 emits (' diff' , {
@@ -99,6 +130,14 @@ watch(() => props, () => {
99130 <div class =" info-left" >{{ filename }}</div >
100131 <div class =" info-left" >{{ newFilename }}</div >
101132 </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 >
102141 <span v-if =" !hideStat" class =" diff-stat" >
103142 <slot name =" stat" :stat =" diffChange.stat" >
104143 <span class =" diff-stat-added" >+{{ diffChange.stat.additionsNum }} additions</span >
@@ -111,6 +150,14 @@ watch(() => props, () => {
111150 <span class =" info-left" >{{ filename }}</span >
112151 <span class =" info-right" >
113152 <span style =" margin-left : 20px ;" >{{ newFilename }}</span >
153+ <span class =" diff-commandbar" >
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 >
160+ </span >
114161 <span v-if =" !hideStat" class =" diff-stat" >
115162 <slot name =" stat" :stat =" diffChange.stat" >
116163 <span class =" diff-stat-added" >+{{ diffChange.stat.additionsNum }} additions</span >
0 commit comments