1
1
<template >
2
2
<section
3
- class =" flex items-center justify-between px-4 py-2 mb-4 sticky top-[70px] dark:bg-gray-700 bg-gray-300 dark:bg-opacity-50 bg-opacity-50 backdrop-blur-sm rounded-md shadow-lg border border-gray-500 w-full z-10"
3
+ class ="
4
+ flex
5
+ items-center
6
+ justify-between
7
+ px-4
8
+ py-2
9
+ mb-4
10
+ sticky
11
+ top-[70px]
12
+ dark:bg-gray-700
13
+ bg-gray-300
14
+ dark:bg-opacity-50
15
+ bg-opacity-50
16
+ backdrop-blur-sm
17
+ rounded-md
18
+ shadow-lg
19
+ border border-gray-500
20
+ w-full
21
+ z-10
22
+ "
4
23
>
5
24
<div class =" flex gap-4" >
6
- <ToggleInSync />
7
25
<NextDiff :click-handler =" goToNextDiff" />
8
26
<PrevDiff :click-handler =" goToPreviousDiff" />
9
27
</div >
14
32
<script lang="ts">
15
33
import Vue from ' vue'
16
34
import PrevDiff from ' ../buttons/prevDiff.vue'
17
- import ToggleInSync from ' ../buttons/toggleInSync.vue'
18
35
import NextDiff from ' ../buttons/nextDiff.vue'
19
36
import CopyLink from ' ../buttons/copyLink.vue'
20
37
import { putToClipboard } from ' ~/helpers/utils'
@@ -23,9 +40,14 @@ export default Vue.extend({
23
40
components: {
24
41
PrevDiff ,
25
42
NextDiff ,
26
- ToggleInSync ,
27
43
CopyLink ,
28
44
},
45
+ props: {
46
+ diffNavigator: {
47
+ type: Object ,
48
+ required: true ,
49
+ },
50
+ },
29
51
data(): DiffActionBarData {
30
52
return {
31
53
copied: false ,
@@ -35,37 +57,7 @@ export default Vue.extend({
35
57
}
36
58
},
37
59
mounted() {
38
- const lhsDiffNode = document .getElementById (' lhsDiff' )
39
- const rhsDiffNode = document .getElementById (' rhsDiff' )
40
- if (lhsDiffNode && rhsDiffNode ) {
41
- const isLHSBigger =
42
- lhsDiffNode .children .length > rhsDiffNode .children .length
43
- let comparator, comparer
44
- if (isLHSBigger ) {
45
- comparer = lhsDiffNode
46
- comparator = rhsDiffNode
47
- } else {
48
- comparer = rhsDiffNode
49
- comparator = lhsDiffNode
50
- }
51
- this .comparator = comparator
52
- this .treeWalker = document .createTreeWalker (
53
- comparer ,
54
- NodeFilter .SHOW_ELEMENT ,
55
- {
56
- acceptNode : (node : Node ) => {
57
- if (
58
- (node as HTMLDivElement ).classList .contains (' bg-red-200' ) ||
59
- (node as HTMLDivElement ).classList .contains (' bg-green-200' )
60
- ) {
61
- return NodeFilter .FILTER_ACCEPT
62
- }
63
- return NodeFilter .FILTER_REJECT
64
- },
65
- }
66
- )
67
- document .addEventListener (' keydown' , this .handleCtrlC )
68
- }
60
+ document .addEventListener (' keydown' , this .handleCtrlC )
69
61
},
70
62
beforeDestroy() {
71
63
document .removeEventListener (' keydown' , this .handleCtrlC )
@@ -96,64 +88,10 @@ export default Vue.extend({
96
88
}, 5000 )
97
89
},
98
90
goToNextDiff() {
99
- const currentNode = this .treeWalker ?.currentNode
100
- const nextNode = this .treeWalker ?.nextNode ()
101
- if (nextNode ) {
102
- const currentNodeIndex = Array .prototype .indexOf .call (
103
- currentNode ?.parentElement ?.children ,
104
- currentNode
105
- )
106
- const nextNodeIndex = Array .prototype .indexOf .call (
107
- nextNode .parentElement ?.children ,
108
- nextNode
109
- )
110
- const comparatorCurrentNode =
111
- this .comparator ?.children [currentNodeIndex ]
112
- const comparatorNextNode = this .comparator ?.children [nextNodeIndex ]
113
- this .toggleDiffHunkAndScrollIntoView (
114
- [
115
- currentNode as HTMLDivElement ,
116
- comparatorCurrentNode as HTMLDivElement ,
117
- ],
118
- [nextNode as HTMLDivElement , comparatorNextNode as HTMLDivElement ]
119
- )
120
- }
91
+ this .diffNavigator .next ()
121
92
},
122
93
goToPreviousDiff() {
123
- const currentNode = this .treeWalker ?.currentNode
124
- const prevNode = this .treeWalker ?.previousNode ()
125
- if (prevNode ) {
126
- const currentNodeIndex = Array .prototype .indexOf .call (
127
- currentNode ?.parentElement ?.children ,
128
- currentNode
129
- )
130
- const prevNodeIndex = Array .prototype .indexOf .call (
131
- prevNode .parentElement ?.children ,
132
- prevNode
133
- )
134
- const comparatorCurrentNode =
135
- this .comparator ?.children [currentNodeIndex ]
136
- const comparatorPrevNode = this .comparator ?.children [prevNodeIndex ]
137
- this .toggleDiffHunkAndScrollIntoView (
138
- [
139
- currentNode as HTMLDivElement ,
140
- comparatorCurrentNode as HTMLDivElement ,
141
- ],
142
- [prevNode as HTMLDivElement , comparatorPrevNode as HTMLDivElement ]
143
- )
144
- }
145
- },
146
- toggleDiffHunkAndScrollIntoView(
147
- unselectedNodes : Array <HTMLDivElement | undefined > = [],
148
- selectedNodes : Array <HTMLDivElement | undefined > = []
149
- ) {
150
- unselectedNodes .forEach ((element ) => {
151
- element ?.querySelector (' p' )?.classList .remove (' selected' )
152
- })
153
- selectedNodes .forEach ((element ) => {
154
- element ?.querySelector (' p' )?.classList .add (' selected' )
155
- element ?.scrollIntoView ()
156
- })
94
+ this .diffNavigator .previous ()
157
95
},
158
96
},
159
97
})
0 commit comments