summaryrefslogtreecommitdiff
path: root/source/features/improve-shortcut-help.tsx
diff options
context:
space:
mode:
authorGravatar yakov116 <16872793+yakov116@users.noreply.github.com> 2020-06-26 04:30:43 -0400
committerGravatar GitHub <noreply@github.com> 2020-06-26 10:30:43 +0200
commitc6c727ca571c91d1ff426e218ccadb075cdb2af6 (patch)
treee1855bb6c6d37f0b28b97be73192316fec2067e5 /source/features/improve-shortcut-help.tsx
parent15da229b3a29483f076782361ac429854f18e18b (diff)
downloadrefined-github-c6c727ca571c91d1ff426e218ccadb075cdb2af6.tar.gz
refined-github-c6c727ca571c91d1ff426e218ccadb075cdb2af6.tar.zst
refined-github-c6c727ca571c91d1ff426e218ccadb075cdb2af6.zip
Lint and avoid errors (#3256)
Diffstat (limited to 'source/features/improve-shortcut-help.tsx')
-rw-r--r--source/features/improve-shortcut-help.tsx23
1 files changed, 13 insertions, 10 deletions
diff --git a/source/features/improve-shortcut-help.tsx b/source/features/improve-shortcut-help.tsx
index 852870ec..51fa9a24 100644
--- a/source/features/improve-shortcut-help.tsx
+++ b/source/features/improve-shortcut-help.tsx
@@ -3,6 +3,7 @@ import React from 'dom-chef';
import select from 'select-dom';
import features from '.';
+import {isEditable} from '../helpers/dom-utils';
function splitKeys(keys: string): DocumentFragment[] {
return keys.split(' ').map(key => <> <kbd>{key}</kbd></>);
@@ -45,17 +46,19 @@ const observer = new MutationObserver(([{target}]) => {
}
});
-function init(): void {
- document.addEventListener('keypress', ({key, target}) => {
- if (key !== '?' || target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement) {
- return;
- }
+function observeShortcutModal({key, target}: KeyboardEvent): void {
+ if (key !== '?' || isEditable(target)) {
+ return;
+ }
- const modal = select('body > details > details-dialog');
- if (modal) {
- observer.observe(modal, {childList: true});
- }
- });
+ const modal = select('body > details > details-dialog');
+ if (modal) {
+ observer.observe(modal, {childList: true});
+ }
+}
+
+function init(): void {
+ document.addEventListener('keypress', observeShortcutModal);
}
void features.add({