Skip to content

Commit 4d53b3f

Browse files
authored
Hotkeys: support contenteditable (#560)
Avoid triggering hotkeys when the active element has `contentEditable=true`. Closes #558
1 parent b78708f commit 4d53b3f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/hotkeys.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export class HotKeysElement extends LitElement {
4242
this.searchHotKeyEnabled = this.config.addons.hotkeys.search.enabled;
4343
}
4444

45+
isInput(element) {
46+
return (
47+
element.tagName === "INPUT" ||
48+
element.tagName === "TEXTAREA" ||
49+
element.tagName === "READTHEDOCS-SEARCH" ||
50+
element.contentEditable === "true"
51+
);
52+
}
53+
4554
_handleKeydown = (e) => {
4655
// Close docdiff with single-stroke `d` (no Ctrl, no Shift, no Alt and no Meta)
4756
// (I'm checking `document.activeElement` to check if it not inside an INPUT to avoid enable/disable while typing on forms)
@@ -54,9 +63,7 @@ export class HotKeysElement extends LitElement {
5463
this.docDiffHotKeyEnabled &&
5564
keyboardEventToString(e) ===
5665
this.config.addons.hotkeys.doc_diff.trigger &&
57-
document.activeElement.tagName !== "INPUT" &&
58-
document.activeElement.tagName !== "TEXTAREA" &&
59-
document.activeElement.tagName !== "READTHEDOCS-SEARCH"
66+
!this.isInput(document.activeElement)
6067
) {
6168
if (this.docDiffEnabled) {
6269
event = new CustomEvent(EVENT_READTHEDOCS_DOCDIFF_HIDE);
@@ -69,9 +76,7 @@ export class HotKeysElement extends LitElement {
6976
if (
7077
this.searchHotKeyEnabled &&
7178
keyboardEventToString(e) === this.config.addons.hotkeys.search.trigger &&
72-
document.activeElement.tagName !== "INPUT" &&
73-
document.activeElement.tagName !== "TEXTAREA" &&
74-
document.activeElement.tagName !== "READTHEDOCS-SEARCH"
79+
!this.isInput(document.activeElement)
7580
) {
7681
event = new CustomEvent(EVENT_READTHEDOCS_SEARCH_SHOW);
7782
}

0 commit comments

Comments
 (0)