From 9dc03f6d4764d589930efbcc809db7076b739624 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 24 Nov 2019 16:23:43 -0500 Subject: Remove wanakana reference from float.html --- ext/fg/float.html | 2 -- 1 file changed, 2 deletions(-) (limited to 'ext/fg/float.html') diff --git a/ext/fg/float.html b/ext/fg/float.html index aec3db20..73118917 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -31,8 +31,6 @@ - - -- cgit v1.2.3 From 7e94fca7c7a07f94de40ddeb56a3f06e43000e25 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 17:29:52 -0500 Subject: Rename extension.js to core.js to better reflect its use --- ext/bg/background.html | 2 +- ext/bg/context.html | 2 +- ext/bg/search.html | 2 +- ext/bg/settings-popup-preview.html | 2 +- ext/bg/settings.html | 2 +- ext/fg/float.html | 2 +- ext/manifest.json | 2 +- ext/mixed/js/core.js | 150 +++++++++++++++++++++++++++++++++++++ ext/mixed/js/extension.js | 150 ------------------------------------- 9 files changed, 157 insertions(+), 157 deletions(-) create mode 100644 ext/mixed/js/core.js delete mode 100644 ext/mixed/js/extension.js (limited to 'ext/fg/float.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index 6e6e7c26..3b337e18 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -18,7 +18,7 @@ - + diff --git a/ext/bg/context.html b/ext/bg/context.html index bd62270b..52ca255d 100644 --- a/ext/bg/context.html +++ b/ext/bg/context.html @@ -178,7 +178,7 @@ - + diff --git a/ext/bg/search.html b/ext/bg/search.html index e819ebe6..16074022 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -60,7 +60,7 @@ - + diff --git a/ext/bg/settings-popup-preview.html b/ext/bg/settings-popup-preview.html index d27a9a33..574b6707 100644 --- a/ext/bg/settings-popup-preview.html +++ b/ext/bg/settings-popup-preview.html @@ -117,7 +117,7 @@ - + diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 262386e9..b2af3759 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -864,7 +864,7 @@ - + diff --git a/ext/fg/float.html b/ext/fg/float.html index 73118917..e04c1402 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -31,7 +31,7 @@ - + diff --git a/ext/manifest.json b/ext/manifest.json index 43a887cd..69ee0c4f 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -18,7 +18,7 @@ "content_scripts": [{ "matches": ["http://*/*", "https://*/*", "file://*/*"], "js": [ - "mixed/js/extension.js", + "mixed/js/core.js", "fg/js/api.js", "fg/js/document.js", "fg/js/frontend-api-receiver.js", diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js new file mode 100644 index 00000000..12ed9c1f --- /dev/null +++ b/ext/mixed/js/core.js @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2019 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +// toIterable is required on Edge for cross-window origin objects. +function toIterable(value) { + if (typeof Symbol !== 'undefined' && typeof value[Symbol.iterator] !== 'undefined') { + return value; + } + + if (value !== null && typeof value === 'object') { + const length = value.length; + if (typeof length === 'number' && Number.isFinite(length)) { + const array = []; + for (let i = 0; i < length; ++i) { + array.push(value[i]); + } + return array; + } + } + + throw new Error('Could not convert to iterable'); +} + +function extensionHasChrome() { + try { + return typeof chrome === 'object' && chrome !== null; + } catch (e) { + return false; + } +} + +function extensionHasBrowser() { + try { + return typeof browser === 'object' && browser !== null; + } catch (e) { + return false; + } +} + +function errorToJson(error) { + return { + name: error.name, + message: error.message, + stack: error.stack + }; +} + +function jsonToError(jsonError) { + const error = new Error(jsonError.message); + error.name = jsonError.name; + error.stack = jsonError.stack; + return error; +} + +function logError(error, alert) { + const manifest = chrome.runtime.getManifest(); + let errorMessage = `${manifest.name} v${manifest.version} has encountered an error.\n`; + errorMessage += `Originating URL: ${window.location.href}\n`; + + const errorString = `${error.toString ? error.toString() : error}`; + const stack = `${error.stack}`.trimRight(); + errorMessage += (!stack.startsWith(errorString) ? `${errorString}\n${stack}` : `${stack}`); + + errorMessage += '\n\nIssues can be reported at https://github.com/FooSoft/yomichan/issues'; + + console.error(errorMessage); + + if (alert) { + window.alert(`${errorString}\n\nCheck the developer console for more details.`); + } +} + +const EXTENSION_IS_BROWSER_EDGE = ( + extensionHasBrowser() && + (!extensionHasChrome() || (typeof chrome.runtime === 'undefined' && typeof browser.runtime !== 'undefined')) +); + +if (EXTENSION_IS_BROWSER_EDGE) { + // Edge does not have chrome defined. + chrome = browser; +} + +function promiseTimeout(delay, resolveValue) { + if (delay <= 0) { + return Promise.resolve(resolveValue); + } + + let timer = null; + let promiseResolve = null; + let promiseReject = null; + + const complete = (callback, value) => { + if (callback === null) { return; } + if (timer !== null) { + window.clearTimeout(timer); + timer = null; + } + promiseResolve = null; + promiseReject = null; + callback(value); + }; + + const resolve = (value) => complete(promiseResolve, value); + const reject = (value) => complete(promiseReject, value); + + const promise = new Promise((resolve, reject) => { + promiseResolve = resolve; + promiseReject = reject; + }); + timer = window.setTimeout(() => { + timer = null; + resolve(resolveValue); + }, delay); + + promise.resolve = resolve; + promise.reject = reject; + + return promise; +} + +function stringReplaceAsync(str, regex, replacer) { + let match; + let index = 0; + const parts = []; + while ((match = regex.exec(str)) !== null) { + parts.push(str.substring(index, match.index), replacer(...match, match.index, str)); + index = regex.lastIndex; + } + if (parts.length === 0) { + return Promise.resolve(str); + } + parts.push(str.substring(index)); + return Promise.all(parts).then(v => v.join('')); +} diff --git a/ext/mixed/js/extension.js b/ext/mixed/js/extension.js deleted file mode 100644 index 12ed9c1f..00000000 --- a/ext/mixed/js/extension.js +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2019 Alex Yatskov - * Author: Alex Yatskov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -// toIterable is required on Edge for cross-window origin objects. -function toIterable(value) { - if (typeof Symbol !== 'undefined' && typeof value[Symbol.iterator] !== 'undefined') { - return value; - } - - if (value !== null && typeof value === 'object') { - const length = value.length; - if (typeof length === 'number' && Number.isFinite(length)) { - const array = []; - for (let i = 0; i < length; ++i) { - array.push(value[i]); - } - return array; - } - } - - throw new Error('Could not convert to iterable'); -} - -function extensionHasChrome() { - try { - return typeof chrome === 'object' && chrome !== null; - } catch (e) { - return false; - } -} - -function extensionHasBrowser() { - try { - return typeof browser === 'object' && browser !== null; - } catch (e) { - return false; - } -} - -function errorToJson(error) { - return { - name: error.name, - message: error.message, - stack: error.stack - }; -} - -function jsonToError(jsonError) { - const error = new Error(jsonError.message); - error.name = jsonError.name; - error.stack = jsonError.stack; - return error; -} - -function logError(error, alert) { - const manifest = chrome.runtime.getManifest(); - let errorMessage = `${manifest.name} v${manifest.version} has encountered an error.\n`; - errorMessage += `Originating URL: ${window.location.href}\n`; - - const errorString = `${error.toString ? error.toString() : error}`; - const stack = `${error.stack}`.trimRight(); - errorMessage += (!stack.startsWith(errorString) ? `${errorString}\n${stack}` : `${stack}`); - - errorMessage += '\n\nIssues can be reported at https://github.com/FooSoft/yomichan/issues'; - - console.error(errorMessage); - - if (alert) { - window.alert(`${errorString}\n\nCheck the developer console for more details.`); - } -} - -const EXTENSION_IS_BROWSER_EDGE = ( - extensionHasBrowser() && - (!extensionHasChrome() || (typeof chrome.runtime === 'undefined' && typeof browser.runtime !== 'undefined')) -); - -if (EXTENSION_IS_BROWSER_EDGE) { - // Edge does not have chrome defined. - chrome = browser; -} - -function promiseTimeout(delay, resolveValue) { - if (delay <= 0) { - return Promise.resolve(resolveValue); - } - - let timer = null; - let promiseResolve = null; - let promiseReject = null; - - const complete = (callback, value) => { - if (callback === null) { return; } - if (timer !== null) { - window.clearTimeout(timer); - timer = null; - } - promiseResolve = null; - promiseReject = null; - callback(value); - }; - - const resolve = (value) => complete(promiseResolve, value); - const reject = (value) => complete(promiseReject, value); - - const promise = new Promise((resolve, reject) => { - promiseResolve = resolve; - promiseReject = reject; - }); - timer = window.setTimeout(() => { - timer = null; - resolve(resolveValue); - }, delay); - - promise.resolve = resolve; - promise.reject = reject; - - return promise; -} - -function stringReplaceAsync(str, regex, replacer) { - let match; - let index = 0; - const parts = []; - while ((match = regex.exec(str)) !== null) { - parts.push(str.substring(index, match.index), replacer(...match, match.index, str)); - index = regex.lastIndex; - } - if (parts.length === 0) { - return Promise.resolve(str); - } - parts.push(str.substring(index)); - return Promise.all(parts).then(v => v.join('')); -} -- cgit v1.2.3 From 96aad50340b4d0374979ac981cd1c481cc8dcd94 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 18:47:16 -0500 Subject: Create DOM utility file --- ext/bg/background.html | 1 + ext/bg/context.html | 1 + ext/bg/search.html | 1 + ext/bg/settings-popup-preview.html | 2 ++ ext/bg/settings.html | 1 + ext/fg/float.html | 1 + ext/fg/js/document.js | 19 ++-------------- ext/fg/js/frontend.js | 14 +----------- ext/manifest.json | 1 + ext/mixed/js/dom.js | 46 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 ext/mixed/js/dom.js (limited to 'ext/fg/float.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index 3b337e18..5a6970c3 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -19,6 +19,7 @@ + diff --git a/ext/bg/context.html b/ext/bg/context.html index 52ca255d..eda09a68 100644 --- a/ext/bg/context.html +++ b/ext/bg/context.html @@ -179,6 +179,7 @@ + diff --git a/ext/bg/search.html b/ext/bg/search.html index 16074022..ef24af89 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -61,6 +61,7 @@ + diff --git a/ext/bg/settings-popup-preview.html b/ext/bg/settings-popup-preview.html index 574b6707..9ca59e44 100644 --- a/ext/bg/settings-popup-preview.html +++ b/ext/bg/settings-popup-preview.html @@ -118,6 +118,8 @@ + + diff --git a/ext/bg/settings.html b/ext/bg/settings.html index b2af3759..908c618c 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -865,6 +865,7 @@ + diff --git a/ext/fg/float.html b/ext/fg/float.html index e04c1402..38439c79 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -32,6 +32,7 @@ + diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 8161c85a..3dd12a40 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -223,7 +223,7 @@ function isPointInRange(x, y, range) { const {node, offset, content} = TextSourceRange.seekForward(range.endContainer, range.endOffset, 1); range.setEnd(node, offset); - if (!isWhitespace(content) && isPointInAnyRect(x, y, range.getClientRects())) { + if (!isWhitespace(content) && DOM.isPointInAnyRect(x, y, range.getClientRects())) { return true; } } finally { @@ -234,7 +234,7 @@ function isPointInRange(x, y, range) { const {node, offset, content} = TextSourceRange.seekBackward(range.startContainer, range.startOffset, 1); range.setStart(node, offset); - if (!isWhitespace(content) && isPointInAnyRect(x, y, range.getClientRects())) { + if (!isWhitespace(content) && DOM.isPointInAnyRect(x, y, range.getClientRects())) { // This purposefully leaves the starting offset as modified and sets the range length to 0. range.setEnd(node, offset); return true; @@ -248,21 +248,6 @@ function isWhitespace(string) { return string.trim().length === 0; } -function isPointInAnyRect(x, y, rects) { - for (const rect of rects) { - if (isPointInRect(x, y, rect)) { - return true; - } - } - return false; -} - -function isPointInRect(x, y, rect) { - return ( - x >= rect.left && x < rect.right && - y >= rect.top && y < rect.bottom); -} - const caretRangeFromPoint = (() => { if (typeof document.caretRangeFromPoint === 'function') { // Chrome, Edge diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 6002dfcb..81c159db 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -159,7 +159,7 @@ class Frontend { this.preventNextClick = false; const primaryTouch = e.changedTouches[0]; - if (Frontend.selectionContainsPoint(window.getSelection(), primaryTouch.clientX, primaryTouch.clientY)) { + if (DOM.isPointInSelection(primaryTouch.clientX, primaryTouch.clientY, window.getSelection())) { return; } @@ -456,18 +456,6 @@ class Frontend { return -1; } - static selectionContainsPoint(selection, x, y) { - for (let i = 0; i < selection.rangeCount; ++i) { - const range = selection.getRangeAt(i); - for (const rect of range.getClientRects()) { - if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) { - return true; - } - } - } - return false; - } - setTextSourceScanLength(textSource, length) { textSource.setEndOffset(length); if (this.ignoreNodes === null || !textSource.range) { diff --git a/ext/manifest.json b/ext/manifest.json index 69ee0c4f..dc670633 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -19,6 +19,7 @@ "matches": ["http://*/*", "https://*/*", "file://*/*"], "js": [ "mixed/js/core.js", + "mixed/js/dom.js", "fg/js/api.js", "fg/js/document.js", "fg/js/frontend-api-receiver.js", diff --git a/ext/mixed/js/dom.js b/ext/mixed/js/dom.js new file mode 100644 index 00000000..4525dace --- /dev/null +++ b/ext/mixed/js/dom.js @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +class DOM { + static isPointInRect(x, y, rect) { + return ( + x >= rect.left && x < rect.right && + y >= rect.top && y < rect.bottom + ); + } + + static isPointInAnyRect(x, y, rects) { + for (const rect of rects) { + if (DOM.isPointInRect(x, y, rect)) { + return true; + } + } + return false; + } + + static isPointInSelection(x, y, selection) { + for (let i = 0; i < selection.rangeCount; ++i) { + const range = selection.getRangeAt(i); + if (DOM.isPointInAnyRect(x, y, range.getClientRects())) { + return true; + } + } + return false; + } +} -- cgit v1.2.3 From 5929018facf792c203e18d3ec690478ee44388e0 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 1 Dec 2019 05:38:23 +0200 Subject: move Display context to a new class --- ext/bg/js/search.js | 1 + ext/bg/search.html | 1 + ext/fg/float.html | 1 + ext/mixed/js/display-context.js | 55 ++++++++++++++++++ ext/mixed/js/display.js | 126 ++++++++++++++++++++-------------------- 5 files changed, 121 insertions(+), 63 deletions(-) create mode 100644 ext/mixed/js/display-context.js (limited to 'ext/fg/float.html') diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index a98d7a9a..00b7ca4b 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -220,6 +220,7 @@ class DisplaySearch extends Display { const {definitions} = await apiTermsFind(query, details, this.optionsContext); this.setContentTerms(definitions, { focus: false, + disableHistory: true, sentence: {text: query, offset: 0}, url: window.location.href }); diff --git a/ext/bg/search.html b/ext/bg/search.html index bac7f01c..fef30456 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -71,6 +71,7 @@ + diff --git a/ext/fg/float.html b/ext/fg/float.html index 38439c79..8cc5a129 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -39,6 +39,7 @@ + diff --git a/ext/mixed/js/display-context.js b/ext/mixed/js/display-context.js new file mode 100644 index 00000000..4b399881 --- /dev/null +++ b/ext/mixed/js/display-context.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +class DisplayContext { + constructor(type, definitions, context) { + this.type = type; + this.definitions = definitions; + this.context = context; + } + + get(key) { + return this.context[key]; + } + + set(key, value) { + this.context[key] = value; + } + + update(data) { + Object.assign(this.context, data); + } + + get previous() { + return this.context.previous; + } + + get next() { + return this.context.next; + } + + static push(self, type, definitions, context) { + const newContext = new DisplayContext(type, definitions, context); + if (self !== null) { + newContext.update({previous: self}); + self.update({next: newContext}); + } + return newContext; + } +} diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 4d32377f..ab50aac0 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -64,27 +64,17 @@ class Display { try { e.preventDefault(); if (!this.context) { return; } - this.context.details.context.next = null; const link = e.target; - const {type, details} = this.context; + this.context.update({ + index: this.entryIndexFind(link), + scroll: this.windowScroll.y + }); const context = { - source: { - type, - details: { - definitions: this.definitions, - context: Object.assign({}, details.context, { - index: this.entryIndexFind(link), - scroll: this.windowScroll.y - }) - } - }, - sentence: details.context.sentence, - url: details.context.url + sentence: this.context.get('sentence'), + url: this.context.get('url') }; - this.windowScroll.toY(0); - const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); this.setContentKanji(definitions, context); } catch (error) { @@ -111,7 +101,7 @@ class Display { async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { try { if (!this.context) { return; } - this.context.details.context.next = null; + const termLookupResults = await this.termLookup(e); if (!termLookupResults) { return; } const {textSource, definitions} = termLookupResults; @@ -119,29 +109,29 @@ class Display { const scannedElement = e.target; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); - const {type, details} = this.context; const context = { - source: disableHistory ? details.context.source : { - type, - details: { - definitions: this.definitions, - context: Object.assign({}, details.context, { - index: this.entryIndexFind(scannedElement), - scroll: this.windowScroll.y - }) - } - }, disableScroll, + disableHistory, sentence, - url: details.context.url + url: this.context.get('url') }; + if (disableHistory) { + Object.assign(context, { + previous: this.context.previous, + next: this.context.next + }); + } else { + this.context.update({ + index: this.entryIndexFind(scannedElement), + scroll: this.windowScroll.y + }); + Object.assign(context, { + previous: this.context + }); + } this.setContentTerms(definitions, context); - if (!disableScroll) { - this.windowScroll.toY(0); - } - if (selectText) { textSource.select(); } @@ -354,16 +344,18 @@ class Display { } this.definitions = definitions; - this.context = { - type: 'terms', - details: {definitions, context} - }; + if (context.disableHistory) { + delete context.disableHistory; + this.context = new DisplayContext('terms', definitions, context); + } else { + this.context = DisplayContext.push(this.context, 'terms', definitions, context); + } const sequence = ++this.sequence; const params = { definitions, - source: context.source, - next: context.next, + source: this.context.previous, + next: this.context.next, addable: options.anki.enable, grouped: options.general.resultOutputMode === 'group', merged: options.general.resultOutputMode === 'merge', @@ -383,6 +375,7 @@ class Display { if (!disableScroll) { this.entryScrollIntoView(index || 0, scroll); } else { + delete context.disableScroll; this.entrySetCurrent(index || 0); } @@ -412,16 +405,18 @@ class Display { } this.definitions = definitions; - this.context = { - type: 'kanji', - details: {definitions, context} - }; + if (context.disableHistory) { + delete context.disableHistory; + this.context = new DisplayContext('kanji', definitions, context); + } else { + this.context = DisplayContext.push(this.context, 'kanji', definitions, context); + } const sequence = ++this.sequence; const params = { definitions, - source: context.source, - next: context.next, + source: this.context.previous, + next: this.context.next, addable: options.anki.enable, debug: options.general.debugInfo }; @@ -531,28 +526,33 @@ class Display { } sourceTermView() { - if (!this.context || !this.context.details.context.source) { return; } - const {type, details} = this.context; - const sourceContext = details.context.source; - sourceContext.details.context.next = { - type, - details: { - definitions: this.definitions, - context: Object.assign({}, details.context, { - index: this.index, - scroll: this.windowScroll.y - }) - } + if (!this.context || !this.context.previous) { return; } + this.context.update({ + index: this.index, + scroll: this.windowScroll.y + }); + const previousContext = this.context.previous; + previousContext.set('disableHistory', true); + const details = { + definitions: previousContext.definitions, + context: previousContext.context }; - this.setContent(sourceContext.type, sourceContext.details); + this.setContent(previousContext.type, details); } nextTermView() { - if (!this.context.details.context.next) { return; } - this.context.details.context.index = this.index; - this.context.details.context.scroll = this.windowScroll.y; - const {type, details} = this.context.details.context.next; - this.setContent(type, details); + if (!this.context || !this.context.next) { return; } + this.context.update({ + index: this.index, + scroll: this.windowScroll.y + }); + const nextContext = this.context.next; + nextContext.set('disableHistory', true); + const details = { + definitions: nextContext.definitions, + context: nextContext.context + }; + this.setContent(nextContext.type, details); } noteTryAdd(mode) { -- cgit v1.2.3