diff --git a/packages/docs/src/.vitepress/theme/components/CodeSandbox.vue b/packages/docs/src/.vitepress/theme/components/CodeSandbox.vue index 17f033f..8c01744 100644 --- a/packages/docs/src/.vitepress/theme/components/CodeSandbox.vue +++ b/packages/docs/src/.vitepress/theme/components/CodeSandbox.vue @@ -13,6 +13,7 @@ maxLines: props.fullHeight ? null : 20, showPrintMargin: false }" + @keydown="handleExecuteHotkey" />
@@ -291,6 +292,30 @@ const handleMessage = (event: MessageEvent) => { } }; +// Platform detection for keyboard shortcuts +const isMac = computed(() => { + // Modern browsers + if ('userAgentData' in navigator) { + return (navigator as any).userAgentData.platform === 'macOS'; + } + + // Legacy browsers + return /Mac|iPod|iPhone|iPad/.test(navigator.platform); +}); + +// Handle keyboard shortcuts for code execution +const handleExecuteHotkey = (event: KeyboardEvent) => { + // Check if the save hotkey was pressed + const isSaveShortcut = event.key.toLowerCase() === 's' && + (isMac.value ? event.metaKey : event.ctrlKey); + + // If the save hotkey was pressed, then execute the code + if (isSaveShortcut) { + event.preventDefault(); + executeCode(); + } +}; + // Lifecycle hooks onMounted(() => { // Check if there's code in the URL hash fragment