Scroll automatically to differences

This commit is contained in:
friebetill 2023-02-05 16:34:39 +08:00
parent b2a91f2670
commit 525b7bf9ae

View file

@ -91,7 +91,10 @@ export class DifferencesView extends ItemView {
)
if (difference != null) {
this.buildDifferenceVisualizer(container, difference)
const differenceContainer = container.createDiv({
cls: 'difference',
})
this.buildDifferenceVisualizer(differenceContainer, difference)
}
if (
line != null &&
@ -105,6 +108,19 @@ export class DifferencesView extends ItemView {
}
}
if (this.fileDifferences.differences.length > 0) {
const containerRect = this.contentEl
.getElementsByClassName('container')[0]
.getBoundingClientRect()
const elementRect = this.contentEl
.getElementsByClassName('difference')[0]
.getBoundingClientRect()
this.contentEl.scrollTo({
top: elementRect.top - containerRect.top - 100,
behavior: 'smooth',
})
}
if (
this.fileDifferences.differences.length === 0 &&
this.showMergeOption &&