|
159 | 159 | v-for="(lineDiff, index) in lhsDiff"
|
160 | 160 | :key="index"
|
161 | 161 | :class="{
|
162 |
| - 'bg-red-200 dark:bg-red-800': lineDiff.includes('isModified'), |
| 162 | + 'bg-red-200 dark:bg-red-800 rounded-sm': |
| 163 | + lineDiff.includes('isModified'), |
163 | 164 | }"
|
164 | 165 | >
|
165 | 166 | <p class="break-all whitespace-pre-wrap" v-html="lineDiff"></p>
|
|
185 | 186 | v-for="(lineDiff, index) in rhsDiff"
|
186 | 187 | :key="index"
|
187 | 188 | :class="{
|
188 |
| - 'bg-green-200 dark:bg-green-700': |
| 189 | + 'bg-green-200 dark:bg-green-700 rounded-sm': |
189 | 190 | lineDiff.includes('isModified'),
|
190 | 191 | }"
|
191 | 192 | >
|
@@ -257,23 +258,35 @@ export default {
|
257 | 258 | }
|
258 | 259 | },
|
259 | 260 | async mounted() {
|
| 261 | + const isLHSBigger = this.lhsDiff.length > this.rhsDiff.length |
| 262 | + const maxLineCount = isLHSBigger ? this.lhsDiff.length : this.rhsDiff.length |
| 263 | + document.documentElement.style.setProperty( |
| 264 | + '--max-line-number-characher', |
| 265 | + `${`${maxLineCount}`.split('').length}ch` |
| 266 | + ) |
| 267 | + const lhsDiffNode = document.getElementById('lhsDiff') |
| 268 | + const rhsDiffNode = document.getElementById('rhsDiff') |
| 269 | + let comparator, comparer |
| 270 | + if (isLHSBigger) { |
| 271 | + comparer = lhsDiffNode |
| 272 | + comparator = rhsDiffNode |
| 273 | + } else { |
| 274 | + comparer = rhsDiffNode |
| 275 | + comparator = lhsDiffNode |
| 276 | + } |
| 277 | + this.comparator = comparator |
260 | 278 | this.treeWalker = document.createTreeWalker(
|
261 |
| - document.getElementById('lhsDiff'), |
| 279 | + comparer, |
262 | 280 | NodeFilter.SHOW_ELEMENT,
|
263 | 281 | {
|
264 | 282 | acceptNode: (node) => {
|
265 |
| - return node.classList.contains('bg-red-200') |
| 283 | + return ( |
| 284 | + node.classList.contains('bg-red-200') || |
| 285 | + node.classList.contains('bg-green-200') |
| 286 | + ) |
266 | 287 | },
|
267 | 288 | }
|
268 | 289 | )
|
269 |
| - const maxLineCount = |
270 |
| - this.lhsDiff.length > this.rhsDiff.length |
271 |
| - ? this.lhsDiff.length |
272 |
| - : this.rhsDiff.length |
273 |
| - document.documentElement.style.setProperty( |
274 |
| - '--max-line-number-characher', |
275 |
| - `${`${maxLineCount}`.split('').length}ch` |
276 |
| - ) |
277 | 290 | const { default: Driver } = await import('driver.js')
|
278 | 291 | const driver = new Driver({
|
279 | 292 | closeBtnText: 'Skip',
|
@@ -362,20 +375,44 @@ export default {
|
362 | 375 | const currentNode = this.treeWalker.currentNode
|
363 | 376 | const nextNode = this.treeWalker.nextNode()
|
364 | 377 | if (nextNode) {
|
| 378 | + const currentNodeIndex = Array.prototype.indexOf.call( |
| 379 | + currentNode.parentElement.children, |
| 380 | + currentNode |
| 381 | + ) |
| 382 | + const nextNodeIndex = Array.prototype.indexOf.call( |
| 383 | + nextNode.parentElement.children, |
| 384 | + nextNode |
| 385 | + ) |
| 386 | + const comparatorCurrentNode = this.comparator.children[currentNodeIndex] |
| 387 | + const comparatorNextNode = this.comparator.children[nextNodeIndex] |
365 | 388 | currentNode.querySelector('p').classList.remove('selected')
|
366 |
| - nextNode.focus() |
| 389 | + comparatorCurrentNode.querySelector('p').classList.remove('selected') |
367 | 390 | nextNode.querySelector('p').classList.add('selected')
|
| 391 | + comparatorNextNode.querySelector('p').classList.add('selected') |
368 | 392 | nextNode.scrollIntoView()
|
| 393 | + comparatorNextNode.scrollIntoView() |
369 | 394 | }
|
370 | 395 | },
|
371 | 396 | goToPreviousDiff() {
|
372 | 397 | const currentNode = this.treeWalker.currentNode
|
373 | 398 | const prevNode = this.treeWalker.previousNode()
|
374 | 399 | if (prevNode) {
|
| 400 | + const currentNodeIndex = Array.prototype.indexOf.call( |
| 401 | + currentNode.parentElement.children, |
| 402 | + currentNode |
| 403 | + ) |
| 404 | + const prevNodeIndex = Array.prototype.indexOf.call( |
| 405 | + prevNode.parentElement.children, |
| 406 | + prevNode |
| 407 | + ) |
| 408 | + const comparatorCurrentNode = this.comparator.children[currentNodeIndex] |
| 409 | + const comparatorPrevNode = this.comparator.children[prevNodeIndex] |
375 | 410 | currentNode.querySelector('p').classList.remove('selected')
|
376 |
| - prevNode.focus() |
| 411 | + comparatorCurrentNode.querySelector('p').classList.remove('selected') |
377 | 412 | prevNode.querySelector('p').classList.add('selected')
|
| 413 | + comparatorPrevNode.querySelector('p').classList.add('selected') |
378 | 414 | prevNode.scrollIntoView()
|
| 415 | + comparatorPrevNode.scrollIntoView() |
379 | 416 | }
|
380 | 417 | },
|
381 | 418 | },
|
|
0 commit comments