mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
054404d716
* fix: Missing + on shared doc shortcut display * fix: Show "+" between shortcut keys on Windows Add shared `shortcutSeparator` constant and use it across all shortcut renderers so Windows displays "Ctrl+K" instead of "CtrlK". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { isMac } from "./browser";
|
|
|
|
/**
|
|
* Returns the display string for the alt key
|
|
*/
|
|
export const altDisplay = isMac ? "⌥" : "Alt";
|
|
|
|
/**
|
|
* Returns the display string for the meta key
|
|
*/
|
|
export const metaDisplay = isMac ? "⌘" : "Ctrl";
|
|
|
|
/**
|
|
* Returns the display string for the control key
|
|
*/
|
|
export const ctrlDisplay = isMac ? "^" : "Ctrl";
|
|
|
|
/**
|
|
* Separator displayed between shortcut keys — "+" on Windows, empty on Mac.
|
|
*/
|
|
export const shortcutSeparator = isMac ? "" : "+";
|
|
|
|
/**
|
|
* Returns the name of the modifier key
|
|
*/
|
|
export const meta = isMac ? "cmd" : "ctrl";
|
|
|
|
/**
|
|
* Returns true if the given event is a modifier key (Cmd on Mac, Ctrl on other platforms).
|
|
* @param event The event to check
|
|
* @returns True if the event is a modifier key
|
|
*/
|
|
export function isModKey(
|
|
event: KeyboardEvent | MouseEvent | React.KeyboardEvent
|
|
) {
|
|
return isMac ? event.metaKey : event.ctrlKey;
|
|
}
|
|
|
|
/**
|
|
* Returns a string with the appropriate display strings for the given key
|
|
*
|
|
* @param key The key to display
|
|
* @param toUpperCase Whether to render single letters as uppercase
|
|
* @returns The display string for the key
|
|
*/
|
|
export function normalizeKeyDisplay(key: string, toUpperCase?: boolean) {
|
|
if (key.length === 1 && toUpperCase) {
|
|
return key.toUpperCase();
|
|
}
|
|
|
|
return key
|
|
.replace(/^Key([A-Z])$/i, (_, letter: string) =>
|
|
toUpperCase ? letter.toUpperCase() : letter
|
|
)
|
|
.replace(/Meta/i, metaDisplay)
|
|
.replace(/Cmd/i, metaDisplay)
|
|
.replace(/Alt/i, altDisplay)
|
|
.replace(/Control/i, ctrlDisplay)
|
|
.replace(/Shift/i, "⇧");
|
|
}
|