Skip to content

Commit

Permalink
feat: use tab / shift-tab to move in Suggestion Modals (#253)
Browse files Browse the repository at this point in the history
* feat: use `tab` / `shift-tab` to move in Suggestion Modals

* fix(prompt): use keyboard event instead of `chooser` for moving
  • Loading branch information
chrisgrieser authored Aug 28, 2024
1 parent 3c1d6ad commit 4533a32
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/commands/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
chooser?: {
useSelectedItem: (evt: KeyboardEvent) => boolean;
moveDown: (count: number) => void;
moveUp: (count: number) => void;
};
}
}

export class JumpModal<T> extends FuzzySuggestModal<string> {
items: Map<string, T>;
onSelect: (value: T, modEvent: boolean | PaneType) => void;
Expand Down Expand Up @@ -33,6 +44,21 @@ export class JumpModal<T> extends FuzzySuggestModal<string> {
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);
}

Expand Down

0 comments on commit 4533a32

Please sign in to comment.