From 407e3143eb29730c531eb9058194db11fedcecb0 Mon Sep 17 00:00:00 2001 From: Michael Clark <5285928+MikesGlitch@users.noreply.github.com> Date: Sat, 7 Sep 2024 19:04:53 +0100 Subject: [PATCH] :electron: Prevent keyboard shortcuts modal when entering shortcut into editable field (#3389) * check input element is focused on before triggering keyboard shortcuts modal * release notes * remove comment --- packages/desktop-client/src/index.tsx | 12 ++++++++++-- packages/desktop-electron/menu.ts | 2 +- upcoming-release-notes/3389.md | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 upcoming-release-notes/3389.md diff --git a/packages/desktop-client/src/index.tsx b/packages/desktop-client/src/index.tsx index 0d64a88cb..c6800e704 100644 --- a/packages/desktop-client/src/index.tsx +++ b/packages/desktop-client/src/index.tsx @@ -70,7 +70,7 @@ handleGlobalEvents(boundActions, store); declare global { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface Window { - __actionsForMenu: BoundActions; + __actionsForMenu: BoundActions & { inputFocused: typeof inputFocused }; $send: typeof send; $query: typeof runQuery; @@ -78,8 +78,16 @@ declare global { } } +function inputFocused() { + return ( + window.document.activeElement.tagName === 'INPUT' || + window.document.activeElement.tagName === 'TEXTAREA' || + (window.document.activeElement as HTMLElement).isContentEditable + ); +} + // Expose this to the main process to menu items can access it -window.__actionsForMenu = boundActions; +window.__actionsForMenu = { ...boundActions, inputFocused }; // Expose send for fun! window.$send = send; diff --git a/packages/desktop-electron/menu.ts b/packages/desktop-electron/menu.ts index 4c44c30ce..5cd99b82e 100644 --- a/packages/desktop-electron/menu.ts +++ b/packages/desktop-electron/menu.ts @@ -179,7 +179,7 @@ export function getMenu( click: function (_menuItem, focusedWin) { if (focusedWin) { focusedWin.webContents.executeJavaScript( - 'window.__actionsForMenu && window.__actionsForMenu.pushModal("keyboard-shortcuts")', + 'window.__actionsForMenu && !window.__actionsForMenu.inputFocused() && window.__actionsForMenu.pushModal("keyboard-shortcuts")', ); } }, diff --git a/upcoming-release-notes/3389.md b/upcoming-release-notes/3389.md new file mode 100644 index 000000000..93fff21f0 --- /dev/null +++ b/upcoming-release-notes/3389.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [MikesGlitch] +--- + +Prevent keyboard shortcuts modal launching when entering shortcut into editable field. -- GitLab