Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove window.disableShortcuts #401

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading