Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Showing keyboard shortcuts on file menu #176

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/suite-base/src/components/AppBar/AppMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
useWorkspaceStore,
} from "@lichtblick/suite-base/context/Workspace/WorkspaceContext";
import { useWorkspaceActions } from "@lichtblick/suite-base/context/Workspace/useWorkspaceActions";
import { formatKeyboardShortcut } from "@lichtblick/suite-base/util/formatKeyboardShortcut";

import { NestedMenuItem } from "./NestedMenuItem";
import { AppBarMenuItem } from "./types";
Expand Down Expand Up @@ -83,6 +84,7 @@ export function AppMenu(props: AppMenuProps): JSX.Element {
type: "item",
label: t("openLocalFile"),
key: "open-file",
shortcut: formatKeyboardShortcut("O", ["Meta"]),
dataTestId: "menu-item-open-local-file",
onClick: () => {
handleNestedMenuClose();
Expand All @@ -93,6 +95,7 @@ export function AppMenu(props: AppMenuProps): JSX.Element {
type: "item",
label: t("openConnection"),
key: "open-connection",
shortcut: formatKeyboardShortcut("O", ["Meta", "Shift"]),
dataTestId: "menu-item-open-connection",
onClick: () => {
dialogActions.dataSource.open("connection");
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-base/src/components/KeyListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function callHandlers(handlers: KeyHandlers | undefined, event: KeyboardEvent):
return;
}

const handler = handlers[event.key] ?? handlers[event.code];
const handler = handlers[event.key.toLowerCase()] ?? handlers[event.code];

if (typeof handler === "function") {
let preventDefault = true;
Expand Down
6 changes: 6 additions & 0 deletions packages/suite-base/src/util/formatKeyboardShortcut.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ describe("formatKeyboardShortcut", () => {
it("formats shortcuts correctly for Windows", () => {
userAgent.mockReturnValue("Windows");
expect(formatKeyboardShortcut("O", ["Shift", "Meta"])).toBe("Shift+Ctrl+O");
expect(formatKeyboardShortcut("O", ["Shift", "Shift", "Shift"])).toBe("Shift+Shift+Shift+O");
expect(formatKeyboardShortcut("O", [])).toBe("O");
});

it("formats shortcuts correctly Linux", () => {
userAgent.mockReturnValue("Linux");
expect(formatKeyboardShortcut("O", ["Shift", "Meta"])).toBe("Shift+Ctrl+O");
expect(formatKeyboardShortcut("O", ["Shift", "Shift", "Shift"])).toBe("Shift+Shift+Shift+O");
expect(formatKeyboardShortcut("O", [])).toBe("O");
});

it("formats shortcuts correctly Mac", () => {
userAgent.mockReturnValue("Mac");
expect(formatKeyboardShortcut("O", ["Shift", "Meta"])).toBe("⇧⌘O");
expect(formatKeyboardShortcut("O", ["Shift", "Shift", "Shift"])).toBe("⇧⇧⇧O");
expect(formatKeyboardShortcut("O", [])).toBe("O");
});
});
Loading