Skip to content

Commit 6b58f4d

Browse files
refactor: remove window.disableShortcuts (#401)
1 parent 21b8b0a commit 6b58f4d

File tree

7 files changed

+17
-24
lines changed

7 files changed

+17
-24
lines changed

public/components/locker/locker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export class Locker {
1111
this.renderUnlock();
1212

1313
document.addEventListener("keydown", (event) => {
14-
if (window.disableShortcuts) {
14+
const isNetworkViewHidden = this.networkView.classList.contains("hidden");
15+
const isTargetInput = event.target.tagName === "INPUT";
16+
const isTargetPopup = event.target.id === "popup--background";
17+
if (isNetworkViewHidden || isTargetInput || isTargetPopup) {
1518
return;
1619
}
1720

public/components/navigation/navigation.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ export class ViewNavigation {
2929
}
3030

3131
document.addEventListener("keydown", (event) => {
32-
if (window.disableShortcuts) {
33-
return;
34-
}
35-
36-
if (window.searchbar.background.classList.contains("show")) {
32+
const isWikiOpen = document.getElementById("documentation-root-element").classList.contains("slide-in");
33+
const isTargetPopup = event.target.id === "popup--background";
34+
const isTargetInput = event.target.tagName === "INPUT";
35+
if (isTargetPopup || isWikiOpen || isTargetInput) {
3736
return;
3837
}
3938

public/components/popup/popup.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export class Popup {
2525
return;
2626
}
2727

28-
window.disableShortcuts = true;
29-
3028
this.templateName = template.name;
3129
this.dom.popup.appendChild(template.HTMLElement);
3230
// TODO: apply additional css customization
@@ -61,7 +59,6 @@ export class Popup {
6159
return;
6260
}
6361

64-
window.disableShortcuts = false;
6562
this.dom.popup.innerHTML = "";
6663
this.templateName = null;
6764
this.#cleanupClickOutside();

public/components/views/settings/settings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const kDefaultHotKeys = {
1414
wiki: "W",
1515
lock: "L"
1616
};
17+
const kShortcutInputTargetIds = new Set(Object.keys(kDefaultHotKeys));
1718

1819
export class Settings {
1920
static defaultMenuName = "info";
@@ -52,7 +53,7 @@ export class Settings {
5253
input.value = "";
5354

5455
const onKeyDown = (event) => {
55-
if (window.disableShortcuts) {
56+
if (kShortcutInputTargetIds.has(event.target.id) === false) {
5657
return;
5758
}
5859

public/components/wiki/wiki.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export class Wiki {
3131
});
3232

3333
document.addEventListener("keydown", (event) => {
34-
if (window.disableShortcuts) {
34+
const isTargetInput = event.target.tagName === "INPUT";
35+
const isTargetPopup = event.target.id === "popup--background";
36+
if (isTargetInput || isTargetPopup) {
3537
return;
3638
}
3739

public/core/network-navigation.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,11 @@ export class NetworkNavigation {
112112
this.#dependenciesMapByLevel.set(0, this.rootNodeParams);
113113

114114
document.addEventListener("keydown", (event) => {
115-
if (window.disableShortcuts) {
116-
return;
117-
}
118-
119115
const isNetworkViewHidden = document.getElementById("network--view").classList.contains("hidden");
120116
const isWikiOpen = document.getElementById("documentation-root-element").classList.contains("slide-in");
121-
const isSearchOpen = window.searchbar.background.classList.contains("show");
122-
if (isNetworkViewHidden || isWikiOpen || isSearchOpen) {
117+
const isTargetPopup = event.target.id === "popup--background";
118+
const isTargetInput = event.target.tagName === "INPUT";
119+
if (isNetworkViewHidden || isWikiOpen || isTargetPopup || isTargetInput) {
123120
return;
124121
}
125122

workspaces/documentation-ui/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,8 @@ export function render(rootElement, options = {}) {
9292
rootElement.appendChild(mainContainer);
9393

9494
document.addEventListener("keydown", (event) => {
95-
if (window.disableShortcuts) {
96-
return;
97-
}
98-
9995
const isWikiOpen = document.getElementById("documentation-root-element").classList.contains("slide-in");
100-
// should not be possible but just in case
101-
const isSearchOpen = window.searchbar.background.classList.contains("show");
102-
if (!isWikiOpen || isSearchOpen) {
96+
if (!isWikiOpen) {
10397
return;
10498
}
10599

0 commit comments

Comments
 (0)