diff options
author | James Maa <jmaa@berkeley.edu> | 2024-06-10 10:59:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 17:59:54 +0000 |
commit | e24075e1a91ab8b58bb5836cf7abcefae5cbf8c3 (patch) | |
tree | 57881c2de6a9d75185a390741d404d61d5c9ce69 /ext/js/app | |
parent | 8eea3661714c64857aa32a8662f7cca6674dd3a4 (diff) |
Add context menu interface for Yomitan (#1028)
* --wip-- [skip ci]
* Draft
* Remove weird code
* Use existing API instead of dulpicating
* Small improvements
* remove console.log
* remove console.log
* Add setting for contextMenu
* Fix test
* Address comments
* Add option-util upgrade
* fix option-utils
Diffstat (limited to 'ext/js/app')
-rw-r--r-- | ext/js/app/frontend.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index 39176475..bdb8cfc5 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -115,6 +115,7 @@ export class Frontend { ['frontendRequestReadyBroadcast', this._onMessageRequestFrontendReadyBroadcast.bind(this)], ['frontendSetAllVisibleOverride', this._onApiSetAllVisibleOverride.bind(this)], ['frontendClearAllVisibleOverride', this._onApiClearAllVisibleOverride.bind(this)], + ['frontendScanSelectedText', this._onApiScanSelectedText.bind(this)], ]); this._hotkeyHandler.registerActions([ @@ -263,6 +264,13 @@ export class Frontend { /** * @returns {void} */ + _onApiScanSelectedText() { + void this._scanSelectedText(false, true, true); + } + + /** + * @returns {void} + */ _onActionScanTextAtSelection() { void this._scanSelectedText(false, false); } @@ -934,13 +942,14 @@ export class Frontend { /** * @param {boolean} allowEmptyRange * @param {boolean} disallowExpandSelection + * @param {boolean} showEmpty show empty popup if no results are found * @returns {Promise<boolean>} */ - async _scanSelectedText(allowEmptyRange, disallowExpandSelection) { + async _scanSelectedText(allowEmptyRange, disallowExpandSelection, showEmpty = false) { const range = this._getFirstSelectionRange(allowEmptyRange); if (range === null) { return false; } const source = disallowExpandSelection ? TextSourceRange.createLazy(range) : TextSourceRange.create(range); - await this._textScanner.search(source, {focus: true, restoreSelection: true}); + await this._textScanner.search(source, {focus: true, restoreSelection: true}, showEmpty); return true; } |