diff options
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(); +                } +            }); +        }); +    }  } |