feat(toolbar): show shortcut hints on hover tooltips
This commit is contained in:
1 parent
f47c209b15
commit
e08eda972b
8 files changed
+137
-21
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatShortcutDisplay, shortcutDisplayKeys } from "@/lib/editor/shortcutDisplay";
|
||||
import { formatShortcutDisplay, formatShortcutTooltip, shortcutDisplayKeys } from "@/lib/editor/shortcutDisplay";
|
||||
|
||||
describe("shortcut display", () => {
|
||||
it("shows the default mouse modifier as Option on macOS and Alt elsewhere", () => {
|
||||
@@ -53,4 +53,13 @@ describe("shortcut display", () => {
|
||||
it("displays multi-stroke shortcuts", () => {
|
||||
expect(formatShortcutDisplay("Ctrl+K Ctrl+C", "Win32")).toBe("Ctrl + K, Ctrl + C");
|
||||
});
|
||||
|
||||
it("formats button tooltips with shortcut hints", () => {
|
||||
expect(formatShortcutTooltip("Execute", "Mod+Enter", "Win32")).toBe("Execute (Ctrl + ↵)");
|
||||
expect(formatShortcutTooltip("Execute", "Mod+Enter", "MacIntel")).toBe("Execute (⌘ ↵)");
|
||||
expect(formatShortcutTooltip("Format SQL", "Shift+Mod+F", "Win32")).toBe("Format SQL (Ctrl + Shift + F)");
|
||||
expect(formatShortcutTooltip("New Query", "")).toBe("New Query");
|
||||
expect(formatShortcutTooltip("New Query", undefined)).toBe("New Query");
|
||||
expect(formatShortcutTooltip("New Query", " ")).toBe("New Query");
|
||||
});
|
||||
});
|
||||
@@ -97,3 +97,9 @@ export function formatShortcutDisplay(shortcut: string, platform = globalThis.na
|
||||
.map((parts) => parts.map((part) => shortcutKeyLabel(part, platform)).join(keySeparator))
|
||||
.join(", ");
|
||||
}
|
||||
|
||||
export function formatShortcutTooltip(label: string, shortcut?: string, platform = globalThis.navigator?.platform || ""): string {
|
||||
if (!shortcut?.trim()) return label;
|
||||
const display = formatShortcutDisplay(shortcut, platform);
|
||||
return display && display !== "—" ? `${label} (${display})` : label;
|
||||
}
|
||||
Reference in new issue
Block a user