From 4533a32e37ecdf2152d01f5ff4f91991b2f1792e Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:59:23 +0200 Subject: [PATCH] feat: use `tab` / `shift-tab` to move in Suggestion Modals (#253) * feat: use `tab` / `shift-tab` to move in Suggestion Modals * fix(prompt): use keyboard event instead of `chooser` for moving --- src/commands/helpers.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/commands/helpers.ts b/src/commands/helpers.ts index 91116d7..5dc4eb9 100644 --- a/src/commands/helpers.ts +++ b/src/commands/helpers.ts @@ -6,6 +6,17 @@ import { type PaneType, } from "obsidian"; +declare module "obsidian" { + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- cannot declare otherwise + interface FuzzySuggestModal { + chooser?: { + useSelectedItem: (evt: KeyboardEvent) => boolean; + moveDown: (count: number) => void; + moveUp: (count: number) => void; + }; + } +} + export class JumpModal extends FuzzySuggestModal { items: Map; onSelect: (value: T, modEvent: boolean | PaneType) => void; @@ -33,6 +44,21 @@ export class JumpModal extends FuzzySuggestModal { return false; }); + // navigate up/down with Tab and Shift+Tab + this.scope.register([], "Tab", (): void => { + document.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown" })); + }); + this.scope.register(["Shift"], "Tab", (): void => { + document.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowUp" })); + }); + instructions.concat([{ + command: "↹ ", + purpose: "Down", + },{ + command: "↹ ", + purpose: "Down", + }]) + this.setInstructions(instructions); }