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; +