diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-15 20:19:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 20:19:56 -0500 |
commit | 0a1664ba296796c347a1690ff5eea71363961806 (patch) | |
tree | e4b472d2d4bb25552ac0e9beb800ae87c61f59ce /ext/mixed/js | |
parent | 9f202313c744412c984c136937976bbdf46faaef (diff) |
Separate close hotkey (#1242)
* Add focusSearchBox hotkey
* Update close hotkey action
* Update hotkeys
Diffstat (limited to 'ext/mixed/js')
-rw-r--r-- | ext/mixed/js/display.js | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 67498d01..8558d849 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -116,7 +116,7 @@ class Display extends EventDispatcher { this._tagNotificationContainer = document.querySelector('#content-footer'); this.registerActions([ - ['close', () => { this.onEscape(); }], + ['close', () => { this.close(); }], ['nextEntry', () => { this._focusEntry(this._index + 1, true); }], ['nextEntry3', () => { this._focusEntry(this._index + 3, true); }], ['previousEntry', () => { this._focusEntry(this._index - 1, true); }], @@ -249,12 +249,6 @@ class Display extends EventDispatcher { yomichan.logError(error); } - onEscape() { - if (this._pageType === 'popup') { - this.close(); - } - } - onKeyDown(e) { const key = e.code; const handlers = this._hotkeys.get(key); @@ -418,8 +412,13 @@ class Display extends EventDispatcher { } close() { - if (this._pageType === 'popup') { - this._invokeOwner('closePopup'); + switch (this._pageType) { + case 'popup': + this._invokeOwner('closePopup'); + break; + case 'search': + this._closeTab(); + break; } } @@ -1904,4 +1903,28 @@ class Display extends EventDispatcher { this._registerHotkey(key, modifiers, action); } } + + async _closeTab() { + const tab = await new Promise((resolve, reject) => { + chrome.tabs.getCurrent((result) => { + const e = chrome.runtime.lastError; + if (e) { + reject(new Error(e.message)); + } else { + resolve(result); + } + }); + }); + const tabId = tab.id; + await new Promise((resolve, reject) => { + chrome.tabs.remove(tabId, () => { + const e = chrome.runtime.lastError; + if (e) { + reject(new Error(e.message)); + } else { + resolve(); + } + }); + }); + } } |