From e37ffb6cf5796fc45787046830d84b9d316c0186 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 28 Nov 2019 12:38:25 +0200 Subject: [PATCH] fix scroll issues in Display.entryScrollIntoView - Save scroll context before scrolling to top - Explicit null check for scroll param to handle scrolling to y=0 correctly --- ext/mixed/js/display.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 2396805a..27100fd2 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -61,7 +61,6 @@ class Display { if (!this.context) { return; } const link = e.target; - this.windowScroll.toY(0); const context = { source: { type: 'terms', @@ -77,6 +76,8 @@ class Display { url: this.context.url }; + this.windowScroll.toY(0); + const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); this.setContentKanji(definitions, context); } catch (error) { @@ -110,10 +111,6 @@ class Display { const scannedElement = e.target; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); - if (!disableScroll) { - this.windowScroll.toY(0); - } - const context = { source: disableHistory ? this.context.source : { type: 'terms', @@ -132,6 +129,10 @@ class Display { this.setContentTerms(definitions, context); + if (!disableScroll) { + this.windowScroll.toY(0); + } + if (selectText) { textSource.select(); } @@ -481,7 +482,7 @@ class Display { this.windowScroll.stop(); let target; - if (scroll) { + if (scroll !== null) { target = scroll; } else { target = index === 0 || entry === null ? 0 : Display.getElementTop(entry);