From a3245059cc4d1af03e8b3576b84cd2ebac4d9ddf Mon Sep 17 00:00:00 2001 From: Violet Millie Date: Fri, 26 Jan 2024 19:01:30 +0000 Subject: [PATCH] Add unfocus keybind --- README.md | 9 +++++---- src/extension/typescript/RegisterKeybinds.ts | 2 ++ .../typescript/keybinds/UnfocusKeybind.ts | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/extension/typescript/keybinds/UnfocusKeybind.ts diff --git a/README.md b/README.md index e202e79..136dae0 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ A Firefox extension adding keybinds to the Akkoma front end. ## Implemented keybinds: -| Action | Keybind | -| -------------------------- | ------- | -| Focus on compose text area | `X` | -| Focus on search bar | `S` | +| Action | Keybind | +| --------------------------- | ------- | +| Focus on compose text area | `X` | +| Focus on search bar | `S` | +| Unfocus from active element | `ESC` | diff --git a/src/extension/typescript/RegisterKeybinds.ts b/src/extension/typescript/RegisterKeybinds.ts index e4392f8..fda1422 100644 --- a/src/extension/typescript/RegisterKeybinds.ts +++ b/src/extension/typescript/RegisterKeybinds.ts @@ -2,9 +2,11 @@ import type KeybindManager from "./KeybindManager"; import ComposeKeybind from "./keybinds/ComposeKeybind"; import SearchKeybind from "./keybinds/SearchKeybind"; +import UnfocusKeybind from "./keybinds/UnfocusKeybind"; export default async function (keybindManager: KeybindManager) { keybindManager.registerKeybind(ComposeKeybind); keybindManager.registerKeybind(SearchKeybind); + keybindManager.registerKeybind(UnfocusKeybind); } diff --git a/src/extension/typescript/keybinds/UnfocusKeybind.ts b/src/extension/typescript/keybinds/UnfocusKeybind.ts new file mode 100644 index 0000000..2a2afe8 --- /dev/null +++ b/src/extension/typescript/keybinds/UnfocusKeybind.ts @@ -0,0 +1,20 @@ +import type { Keybind } from "../KeybindManager"; + +const keybind: Keybind = { + key: "Escape", + + allowWhileComposing: true, + + execute: function () { + const activeElement = document.activeElement as HTMLElement; + + if (!activeElement) { + return; + } + + activeElement.blur(); + }, +}; + +export default keybind; +