Skip to content

Commit

Permalink
refactor: remove window.disableShortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly committed Jul 14, 2024
1 parent 21b8b0a commit 914bb8a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
5 changes: 4 additions & 1 deletion public/components/locker/locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export class Locker {
this.renderUnlock();

document.addEventListener("keydown", (event) => {
if (window.disableShortcuts) {
const isNetworkViewHidden = this.networkView.classList.contains("hidden");
const isTargetInput = event.target.tagName === "INPUT";
const isTargetPopup = event.target.id === "popup--background";
if (isNetworkViewHidden || isTargetInput || isTargetPopup) {
return;
}

Expand Down
9 changes: 4 additions & 5 deletions public/components/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ export class ViewNavigation {
}

document.addEventListener("keydown", (event) => {
if (window.disableShortcuts) {
return;
}

if (window.searchbar.background.classList.contains("show")) {
const isWikiOpen = document.getElementById("documentation-root-element").classList.contains("slide-in");
const isTargetPopup = event.target.id === "popup--background";
const isTargetInput = event.target.tagName === "INPUT";
if (isTargetPopup || isWikiOpen || isTargetInput) {
return;
}

Expand Down
3 changes: 0 additions & 3 deletions public/components/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class Popup {
return;
}

window.disableShortcuts = true;

this.templateName = template.name;
this.dom.popup.appendChild(template.HTMLElement);
// TODO: apply additional css customization
Expand Down Expand Up @@ -61,7 +59,6 @@ export class Popup {
return;
}

window.disableShortcuts = false;
this.dom.popup.innerHTML = "";
this.templateName = null;
this.#cleanupClickOutside();
Expand Down
3 changes: 2 additions & 1 deletion public/components/views/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const kDefaultHotKeys = {
wiki: "W",
lock: "L"
};
const kShortcutInputTargetIds = new Set(Object.keys(kDefaultHotKeys));

export class Settings {
static defaultMenuName = "info";
Expand Down Expand Up @@ -52,7 +53,7 @@ export class Settings {
input.value = "";

const onKeyDown = (event) => {
if (window.disableShortcuts) {
if (kShortcutInputTargetIds.has(event.target.id) === false) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion public/components/wiki/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export class Wiki {
});

document.addEventListener("keydown", (event) => {
if (window.disableShortcuts) {
const isTargetInput = event.target.tagName === "INPUT";
const isTargetPopup = event.target.id === "popup--background";
if (isTargetInput || isTargetPopup) {
return;
}

Expand Down
9 changes: 3 additions & 6 deletions public/core/network-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@ export class NetworkNavigation {
this.#dependenciesMapByLevel.set(0, this.rootNodeParams);

document.addEventListener("keydown", (event) => {
if (window.disableShortcuts) {
return;
}

const isNetworkViewHidden = document.getElementById("network--view").classList.contains("hidden");
const isWikiOpen = document.getElementById("documentation-root-element").classList.contains("slide-in");
const isSearchOpen = window.searchbar.background.classList.contains("show");
if (isNetworkViewHidden || isWikiOpen || isSearchOpen) {
const isTargetPopup = event.target.id === "popup--background";
const isTargetInput = event.target.tagName === "INPUT";
if (isNetworkViewHidden || isWikiOpen || isTargetPopup || isTargetInput) {
return;
}

Expand Down
8 changes: 1 addition & 7 deletions workspaces/documentation-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,8 @@ export function render(rootElement, options = {}) {
rootElement.appendChild(mainContainer);

document.addEventListener("keydown", (event) => {
if (window.disableShortcuts) {
return;
}

const isWikiOpen = document.getElementById("documentation-root-element").classList.contains("slide-in");
// should not be possible but just in case
const isSearchOpen = window.searchbar.background.classList.contains("show");
if (!isWikiOpen || isSearchOpen) {
if (!isWikiOpen) {
return;
}

Expand Down

0 comments on commit 914bb8a

Please sign in to comment.