diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/backend.js | 6 | ||||
-rw-r--r-- | ext/bg/js/search-query-parser.js | 6 | ||||
-rw-r--r-- | ext/fg/js/popup-proxy-host.js | 10 |
3 files changed, 15 insertions, 7 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 5b7ab084..4595dbb3 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -120,7 +120,8 @@ class Backend { this.clipboardMonitor.onClipboardText = this._onClipboardText.bind(this); this._sendMessageAllTabs('backendPrepared'); - chrome.runtime.sendMessage({action: 'backendPrepared'}); + const callback = () => this.checkLastError(chrome.runtime.lastError); + chrome.runtime.sendMessage({action: 'backendPrepared'}, callback); } _sendMessageAllTabs(action, params={}) { @@ -281,7 +282,8 @@ class Backend { _onApiYomichanCoreReady(_params, sender) { // tab ID isn't set in background (e.g. browser_action) if (typeof sender.tab === 'undefined') { - chrome.runtime.sendMessage({action: 'backendPrepared'}); + const callback = () => this.checkLastError(chrome.runtime.lastError); + chrome.runtime.sendMessage({action: 'backendPrepared'}, callback); return Promise.resolve(); } diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 11c7baa2..c64d0fea 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -16,7 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -/*global apiTermsFind, apiOptionsSet, apiTextParse, apiTextParseMecab, TextScanner, QueryParserGenerator*/ +/*global apiTermsFind, apiOptionsSet, apiTextParse, apiTextParseMecab, TextScanner, QueryParserGenerator, docSentenceExtract*/ class QueryParser extends TextScanner { constructor(search) { @@ -55,12 +55,14 @@ class QueryParser extends TextScanner { const {definitions, length} = await apiTermsFind(searchText, {}, this.search.getOptionsContext()); if (definitions.length === 0) { return null; } + const sentence = docSentenceExtract(textSource, this.search.options.anki.sentenceExt); + textSource.setEndOffset(length); this.search.setContent('terms', {definitions, context: { focus: false, disableHistory: cause === 'mouse', - sentence: {text: searchText, offset: 0}, + sentence, url: window.location.href }}); diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index bef2cb16..7d86aa67 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -116,6 +116,7 @@ class PopupProxyHost { async _onApiContainsPoint({id, x, y}) { const popup = this._getPopup(id); + [x, y] = PopupProxyHost._convertPopupPointToRootPagePoint(popup, x, y); return await popup.containsPoint(x, y); } @@ -152,14 +153,17 @@ class PopupProxyHost { } static _convertJsonRectToDOMRect(popup, jsonRect) { - let x = jsonRect.x; - let y = jsonRect.y; + const [x, y] = PopupProxyHost._convertPopupPointToRootPagePoint(popup, jsonRect.x, jsonRect.y); + return new DOMRect(x, y, jsonRect.width, jsonRect.height); + } + + static _convertPopupPointToRootPagePoint(popup, x, y) { if (popup.parent !== null) { const popupRect = popup.parent.getContainerRect(); x += popupRect.x; y += popupRect.y; } - return new DOMRect(x, y, jsonRect.width, jsonRect.height); + return [x, y]; } static _popupCanShow(popup) { |