2222 "
2323 >
2424 <div class =" flex gap-4" >
25- <div
26- id =" toggleScrollInSyncSection"
27- class =" inline-flex items-center gap-1"
28- >
29- <label
30- for =" toggleScrollInSync"
31- class =" text-gray-800 select-none dark:text-gray-50"
32- >
33- Scroll in sync
34- </label >
35- <input
36- id =" toggleScrollInSync"
37- type =" checkbox"
38- checked
39- class =" form-checkbox"
40- @click =" toggleInSyncScroll"
41- />
42- </div >
43- <div id =" nextDiffSection" class =" inline-flex items-center gap-1" >
44- <button
45- id =" nextDiff"
46- class =" inline-flex items-center justify-center px-1 py-1 text-sm text-gray-600 transition-transform transform bg-gray-300 border border-gray-800 rounded-sm outline-none dark:border-gray-400 dark:text-white dark:bg-gray-800 align-center focus:ring-4 active:scale-y-75 hover:scale-105 hover:shadow-lg"
47- aria-label =" Go to next diff"
48- type =" button"
49- @click =" goToNextDiff"
50- >
51- Next diff
52- <svg
53- class =" w-4 h-4"
54- fill =" none"
55- stroke =" currentColor"
56- viewBox =" 0 0 24 24"
57- xmlns =" http://www.w3.org/2000/svg"
58- >
59- <path
60- stroke-linecap =" round"
61- stroke-linejoin =" round"
62- stroke-width =" 2"
63- d =" M16 17l-4 4m0 0l-4-4m4 4V3"
64- ></path >
65- </svg >
66- </button >
67- </div >
68- <div id =" prevDiffSection" class =" inline-flex items-center gap-1" >
69- <button
70- id =" prevDiff"
71- class =" inline-flex items-center justify-center px-1 py-1 text-sm text-gray-600 transition-transform transform bg-gray-300 border border-gray-800 rounded-sm outline-none dark:border-gray-400 dark:text-white dark:bg-gray-800 align-center focus:ring-4 active:scale-y-75 hover:scale-105 hover:shadow-lg"
72- aria-label =" Go to previous diff"
73- type =" button"
74- @click =" goToPreviousDiff"
75- >
76- Previous diff
77- <svg
78- class =" w-4 h-4"
79- fill =" none"
80- stroke =" currentColor"
81- viewBox =" 0 0 24 24"
82- xmlns =" http://www.w3.org/2000/svg"
83- >
84- <path
85- stroke-linecap =" round"
86- stroke-linejoin =" round"
87- stroke-width =" 2"
88- d =" M8 7l4-4m0 0l4 4m-4-4v18"
89- ></path >
90- </svg >
91- </button >
92- </div >
93- </div >
94- <div >
95- <button
96- type =" button"
97- class =" inline-flex items-center justify-center gap-1 p-2 text-sm transition-transform transform rounded-md shadow outline-none justify-self-end focus:ring-4 active:scale-y-75 hover:scale-105 hover:shadow-lg copy-uri-button"
98- aria-label =" Copy url to clipboard"
99- :class =" {
100- 'bg-blue-500 text-white': !copied,
101- 'bg-green-500 text-gray-800': copied,
102- }"
103- @click =" copyUrlToClipboard"
104- >
105- <span v-show =" copied" class =" inline" >
106- <svg
107- class =" w-4 h-4"
108- fill =" none"
109- stroke =" currentColor"
110- viewBox =" 0 0 24 24"
111- xmlns =" http://www.w3.org/2000/svg"
112- >
113- <path
114- stroke-linecap =" round"
115- stroke-linejoin =" round"
116- stroke-width =" 2"
117- d =" M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"
118- ></path >
119- </svg >
120- </span >
121- <span v-show =" copied" class =" hidden md:inline-block" >Copied</span >
122- <span v-show =" !copied" class =" inline" >
123- <svg
124- class =" w-4 h-4"
125- fill =" none"
126- stroke =" currentColor"
127- viewBox =" 0 0 24 24"
128- xmlns =" http://www.w3.org/2000/svg"
129- >
130- <path
131- stroke-linecap =" round"
132- stroke-linejoin =" round"
133- stroke-width =" 2"
134- d =" M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"
135- ></path >
136- </svg >
137- </span >
138- <span v-show =" !copied" class =" hidden md:inline-block" >Copy link</span >
139- </button >
25+ <ToggleInSync :click-handler =" toggleInSyncScroll" />
26+ <NextDiff :click-handler =" goToNextDiff" />
27+ <PrevDiff :click-handler =" goToPreviousDiff" />
14028 </div >
29+ <CopyLink :click-handler =" copyUrlToClipboard" :copied =" copied" ></CopyLink >
14130 </section >
14231</template >
14332
14433<script >
34+ import PrevDiff from ' ./buttons/prevDiff.vue'
35+ import ToggleInSync from ' ./buttons/toggleInSync.vue'
36+ import NextDiff from ' ./buttons/nextDiff.vue'
37+ import CopyLink from ' ./buttons/copyLink.vue'
14538import { putToClipboard } from ' ~/helpers/utils'
14639export default {
40+ components: { PrevDiff, NextDiff, ToggleInSync, CopyLink },
14741 data () {
14842 return {
14943 copied: this .copied ,
@@ -210,12 +104,10 @@ export default {
210104 )
211105 const comparatorCurrentNode = this .comparator .children [currentNodeIndex]
212106 const comparatorNextNode = this .comparator .children [nextNodeIndex]
213- currentNode .querySelector (' p' ).classList .remove (' selected' )
214- comparatorCurrentNode .querySelector (' p' ).classList .remove (' selected' )
215- nextNode .querySelector (' p' ).classList .add (' selected' )
216- comparatorNextNode .querySelector (' p' ).classList .add (' selected' )
217- nextNode .scrollIntoView ()
218- comparatorNextNode .scrollIntoView ()
107+ this .toggleDiffHunkAndScrollIntoView (
108+ [currentNode, comparatorCurrentNode],
109+ [nextNode, comparatorNextNode]
110+ )
219111 }
220112 },
221113 goToPreviousDiff () {
@@ -232,14 +124,21 @@ export default {
232124 )
233125 const comparatorCurrentNode = this .comparator .children [currentNodeIndex]
234126 const comparatorPrevNode = this .comparator .children [prevNodeIndex]
235- currentNode .querySelector (' p' ).classList .remove (' selected' )
236- comparatorCurrentNode .querySelector (' p' ).classList .remove (' selected' )
237- prevNode .querySelector (' p' ).classList .add (' selected' )
238- comparatorPrevNode .querySelector (' p' ).classList .add (' selected' )
239- prevNode .scrollIntoView ()
240- comparatorPrevNode .scrollIntoView ()
127+ this .toggleDiffHunkAndScrollIntoView (
128+ [currentNode, comparatorCurrentNode],
129+ [prevNode, comparatorPrevNode]
130+ )
241131 }
242132 },
133+ toggleDiffHunkAndScrollIntoView (unselectedNodes , selectedNodes ) {
134+ unselectedNodes .forEach ((element ) => {
135+ element .querySelector (' p' ).classList .remove (' selected' )
136+ })
137+ selectedNodes .forEach ((element ) => {
138+ element .querySelector (' p' ).classList .add (' selected' )
139+ element .scrollIntoView ()
140+ })
141+ },
243142 },
244143}
245144 </script >
0 commit comments