aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-15 20:19:56 -0500
committerGitHub <noreply@github.com>2021-01-15 20:19:56 -0500
commit0a1664ba296796c347a1690ff5eea71363961806 (patch)
treee4b472d2d4bb25552ac0e9beb800ae87c61f59ce
parent9f202313c744412c984c136937976bbdf46faaef (diff)
Separate close hotkey (#1242)
* Add focusSearchBox hotkey * Update close hotkey action * Update hotkeys
-rw-r--r--ext/bg/data/options-schema.json3
-rw-r--r--ext/bg/js/options.js3
-rw-r--r--ext/bg/js/search.js21
-rw-r--r--ext/bg/settings2.html3
-rw-r--r--ext/mixed/js/display.js41
-rw-r--r--test/test-options-util.js3
6 files changed, 52 insertions, 22 deletions
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json
index 8c00d455..405d62a9 100644
--- a/ext/bg/data/options-schema.json
+++ b/ext/bg/data/options-schema.json
@@ -971,7 +971,8 @@
}
},
"default": [
- {"action": "close", "key": "Escape", "modifiers": [], "scopes": ["popup", "search"], "enabled": true},
+ {"action": "close", "key": "Escape", "modifiers": [], "scopes": ["popup"], "enabled": true},
+ {"action": "focusSearchBox", "key": "Escape", "modifiers": [], "scopes": ["search"], "enabled": true},
{"action": "previousEntry3", "key": "PageUp", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "nextEntry3", "key": "PageDown", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "lastEntry", "key": "End", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index cbc390da..964c346c 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -716,7 +716,8 @@ class OptionsUtil {
profile.options.general.popupActionBarLocation = 'top';
profile.options.inputs = {
hotkeys: [
- {action: 'close', key: 'Escape', modifiers: [], scopes: ['popup', 'search'], enabled: true},
+ {action: 'close', key: 'Escape', modifiers: [], scopes: ['popup'], enabled: true},
+ {action: 'focusSearchBox', key: 'Escape', modifiers: [], scopes: ['search'], enabled: true},
{action: 'previousEntry3', key: 'PageUp', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'nextEntry3', key: 'PageDown', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'lastEntry', key: 'End', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 340b86ce..00148418 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -43,6 +43,10 @@ class DisplaySearch extends Display {
}
});
this.autoPlayAudioDelay = 0;
+
+ this.registerActions([
+ ['focusSearchBox', this._onActionFocusSearchBox.bind(this)]
+ ]);
}
async prepare() {
@@ -77,15 +81,6 @@ class DisplaySearch extends Display {
this._isPrepared = true;
}
- onEscape() {
- if (this._queryInput === null) {
- return;
- }
-
- this._queryInput.focus();
- this._queryInput.select();
- }
-
onKeyDown(e) {
if (
!super.onKeyDown(e) &&
@@ -110,6 +105,14 @@ class DisplaySearch extends Display {
return query;
}
+ // Actions
+
+ _onActionFocusSearchBox() {
+ if (this._queryInput === null) { return; }
+ this._queryInput.focus();
+ this._queryInput.select();
+ }
+
// Private
async _onOptionsUpdated() {
diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html
index f44b7eab..0beef025 100644
--- a/ext/bg/settings2.html
+++ b/ext/bg/settings2.html
@@ -2871,7 +2871,8 @@
<div class="hotkey-list-item-action-cell">
<select class="hotkey-list-item-action">
<option value="">None</option>
- <option value="close">Close popup</option>
+ <option value="close">Close</option>
+ <option value="focusSearchBox">Focus search box</option>
<option value="nextEntry">Go to next entry</option>
<option value="nextEntry3">Go to next entry (x3)</option>
<option value="previousEntry">Go to previous entry</option>
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();
+ }
+ });
+ });
+ }
}
diff --git a/test/test-options-util.js b/test/test-options-util.js
index e245a285..f27fbcd4 100644
--- a/test/test-options-util.js
+++ b/test/test-options-util.js
@@ -440,7 +440,8 @@ function createProfileOptionsUpdatedTestData1() {
},
inputs: {
hotkeys: [
- {action: 'close', key: 'Escape', modifiers: [], scopes: ['popup', 'search'], enabled: true},
+ {action: 'close', key: 'Escape', modifiers: [], scopes: ['popup'], enabled: true},
+ {action: 'focusSearchBox', key: 'Escape', modifiers: [], scopes: ['search'], enabled: true},
{action: 'previousEntry3', key: 'PageUp', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'nextEntry3', key: 'PageDown', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'lastEntry', key: 'End', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},