Add control S hotkey to execute code
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
maxLines: props.fullHeight ? null : 20,
|
maxLines: props.fullHeight ? null : 20,
|
||||||
showPrintMargin: false
|
showPrintMargin: false
|
||||||
}"
|
}"
|
||||||
|
@keydown="handleExecuteHotkey"
|
||||||
/>
|
/>
|
||||||
<div class="editor-buttons">
|
<div class="editor-buttons">
|
||||||
<button v-if="!hideRunButton" @click="executeCode" class="primary-button">Run Code</button>
|
<button v-if="!hideRunButton" @click="executeCode" class="primary-button">Run Code</button>
|
||||||
@@ -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
|
// Lifecycle hooks
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// Check if there's code in the URL hash fragment
|
// Check if there's code in the URL hash fragment
|
||||||
|
|||||||
Reference in New Issue
Block a user