From 525b7bf9aedb5ffc02749f19ce544119ad15d85a Mon Sep 17 00:00:00 2001 From: friebetill Date: Sun, 5 Feb 2023 16:34:39 +0800 Subject: [PATCH] Scroll automatically to differences --- src/components/differences_view.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/differences_view.ts b/src/components/differences_view.ts index d7cfbb7..fed4084 100644 --- a/src/components/differences_view.ts +++ b/src/components/differences_view.ts @@ -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 &&