11<template >
22 <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+ "
423 >
524 <div class =" flex gap-4" >
6- <ToggleInSync />
725 <NextDiff :click-handler =" goToNextDiff" />
826 <PrevDiff :click-handler =" goToPreviousDiff" />
927 </div >
1432<script lang="ts">
1533import Vue from ' vue'
1634import PrevDiff from ' ../buttons/prevDiff.vue'
17- import ToggleInSync from ' ../buttons/toggleInSync.vue'
1835import NextDiff from ' ../buttons/nextDiff.vue'
1936import CopyLink from ' ../buttons/copyLink.vue'
2037import { putToClipboard } from ' ~/helpers/utils'
@@ -23,9 +40,14 @@ export default Vue.extend({
2340 components: {
2441 PrevDiff ,
2542 NextDiff ,
26- ToggleInSync ,
2743 CopyLink ,
2844 },
45+ props: {
46+ diffNavigator: {
47+ type: Object ,
48+ required: true ,
49+ },
50+ },
2951 data(): DiffActionBarData {
3052 return {
3153 copied: false ,
@@ -35,37 +57,7 @@ export default Vue.extend({
3557 }
3658 },
3759 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 )
6961 },
7062 beforeDestroy() {
7163 document .removeEventListener (' keydown' , this .handleCtrlC )
@@ -96,64 +88,10 @@ export default Vue.extend({
9688 }, 5000 )
9789 },
9890 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 ()
12192 },
12293 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 ()
15795 },
15896 },
15997})
0 commit comments