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
This commit is contained in:
siikamiika 2019-11-28 12:38:25 +02:00
parent 5a1046bc90
commit e37ffb6cf5

View File

@ -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);