Skip to content

Vizel API / core/src / formatVizelShortcut

Function: formatVizelShortcut()

ts
function formatVizelShortcut(shortcut): string;

Defined in: packages/core/src/utils/keyboard.ts:71

Format a keyboard shortcut for the current platform.

Accepts either a plain shortcut string or a VizelPlatformShortcut object. For the object form, the function selects the mac or other string via isVizelMacPlatform. Both separators are recognized: the + notation used by the legacy slash hints and the - notation used by Tiptap keymaps (e.g. Mod-Alt-1).

Converts generic modifier names to platform-appropriate symbols:

  • macOS: Mod→⌘, Shift→⇧, Alt→⌥, keys joined without separator
  • Other: Mod→Ctrl, Shift→Shift, Alt→Alt, keys joined with +

Parameters

ParameterType
shortcutstring | VizelPlatformShortcut

Returns

string

Example

ts
// On macOS:
formatVizelShortcut("Mod+B")                       // "⌘B"
formatVizelShortcut("Mod-Alt-1")                   // "⌥⌘1"
formatVizelShortcut({ mac: "Mod-B", other: "Mod-B" }) // "⌘B"

// On Windows/Linux:
formatVizelShortcut("Mod+B")                       // "Ctrl+B"
formatVizelShortcut("Mod-Alt-1")                   // "Ctrl+Alt+1"
formatVizelShortcut({ mac: "Mod-B", other: "Ctrl-H" }) // "Ctrl+H"

Released under the MIT License.