Separate close hotkey (#1242)
* Add focusSearchBox hotkey * Update close hotkey action * Update hotkeys
This commit is contained in:
parent
9f202313c7
commit
0a1664ba29
@ -971,7 +971,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"default": [
|
"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": "previousEntry3", "key": "PageUp", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
|
||||||
{"action": "nextEntry3", "key": "PageDown", "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},
|
{"action": "lastEntry", "key": "End", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
|
||||||
|
@ -716,7 +716,8 @@ class OptionsUtil {
|
|||||||
profile.options.general.popupActionBarLocation = 'top';
|
profile.options.general.popupActionBarLocation = 'top';
|
||||||
profile.options.inputs = {
|
profile.options.inputs = {
|
||||||
hotkeys: [
|
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: 'previousEntry3', key: 'PageUp', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
||||||
{action: 'nextEntry3', key: 'PageDown', 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},
|
{action: 'lastEntry', key: 'End', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
||||||
|
@ -43,6 +43,10 @@ class DisplaySearch extends Display {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.autoPlayAudioDelay = 0;
|
this.autoPlayAudioDelay = 0;
|
||||||
|
|
||||||
|
this.registerActions([
|
||||||
|
['focusSearchBox', this._onActionFocusSearchBox.bind(this)]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async prepare() {
|
async prepare() {
|
||||||
@ -77,15 +81,6 @@ class DisplaySearch extends Display {
|
|||||||
this._isPrepared = true;
|
this._isPrepared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onEscape() {
|
|
||||||
if (this._queryInput === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._queryInput.focus();
|
|
||||||
this._queryInput.select();
|
|
||||||
}
|
|
||||||
|
|
||||||
onKeyDown(e) {
|
onKeyDown(e) {
|
||||||
if (
|
if (
|
||||||
!super.onKeyDown(e) &&
|
!super.onKeyDown(e) &&
|
||||||
@ -110,6 +105,14 @@ class DisplaySearch extends Display {
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
_onActionFocusSearchBox() {
|
||||||
|
if (this._queryInput === null) { return; }
|
||||||
|
this._queryInput.focus();
|
||||||
|
this._queryInput.select();
|
||||||
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
async _onOptionsUpdated() {
|
async _onOptionsUpdated() {
|
||||||
|
@ -2871,7 +2871,8 @@
|
|||||||
<div class="hotkey-list-item-action-cell">
|
<div class="hotkey-list-item-action-cell">
|
||||||
<select class="hotkey-list-item-action">
|
<select class="hotkey-list-item-action">
|
||||||
<option value="">None</option>
|
<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="nextEntry">Go to next entry</option>
|
||||||
<option value="nextEntry3">Go to next entry (x3)</option>
|
<option value="nextEntry3">Go to next entry (x3)</option>
|
||||||
<option value="previousEntry">Go to previous entry</option>
|
<option value="previousEntry">Go to previous entry</option>
|
||||||
|
@ -116,7 +116,7 @@ class Display extends EventDispatcher {
|
|||||||
this._tagNotificationContainer = document.querySelector('#content-footer');
|
this._tagNotificationContainer = document.querySelector('#content-footer');
|
||||||
|
|
||||||
this.registerActions([
|
this.registerActions([
|
||||||
['close', () => { this.onEscape(); }],
|
['close', () => { this.close(); }],
|
||||||
['nextEntry', () => { this._focusEntry(this._index + 1, true); }],
|
['nextEntry', () => { this._focusEntry(this._index + 1, true); }],
|
||||||
['nextEntry3', () => { this._focusEntry(this._index + 3, true); }],
|
['nextEntry3', () => { this._focusEntry(this._index + 3, true); }],
|
||||||
['previousEntry', () => { this._focusEntry(this._index - 1, true); }],
|
['previousEntry', () => { this._focusEntry(this._index - 1, true); }],
|
||||||
@ -249,12 +249,6 @@ class Display extends EventDispatcher {
|
|||||||
yomichan.logError(error);
|
yomichan.logError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
onEscape() {
|
|
||||||
if (this._pageType === 'popup') {
|
|
||||||
this.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onKeyDown(e) {
|
onKeyDown(e) {
|
||||||
const key = e.code;
|
const key = e.code;
|
||||||
const handlers = this._hotkeys.get(key);
|
const handlers = this._hotkeys.get(key);
|
||||||
@ -418,8 +412,13 @@ class Display extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
if (this._pageType === 'popup') {
|
switch (this._pageType) {
|
||||||
this._invokeOwner('closePopup');
|
case 'popup':
|
||||||
|
this._invokeOwner('closePopup');
|
||||||
|
break;
|
||||||
|
case 'search':
|
||||||
|
this._closeTab();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1904,4 +1903,28 @@ class Display extends EventDispatcher {
|
|||||||
this._registerHotkey(key, modifiers, action);
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,8 @@ function createProfileOptionsUpdatedTestData1() {
|
|||||||
},
|
},
|
||||||
inputs: {
|
inputs: {
|
||||||
hotkeys: [
|
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: 'previousEntry3', key: 'PageUp', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
||||||
{action: 'nextEntry3', key: 'PageDown', 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},
|
{action: 'lastEntry', key: 'End', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
||||||
|
Loading…
Reference in New Issue
Block a user