Skip to content

Commit 7079bd4

Browse files
committed
2 parents 49a8a04 + 383fff7 commit 7079bd4

File tree

1 file changed

+55
-14
lines changed

1 file changed

+55
-14
lines changed

client/components/open/editors/UndoRedo.vue

+55-14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
size="sm"
44
orientation="horizontal"
55
>
6-
<UButton
7-
:disabled="!canUndo"
8-
color="white"
9-
icon="i-material-symbols-undo"
10-
class="disabled:text-gray-500"
11-
@click="undo"
12-
/>
13-
<UButton
14-
:disabled="!canRedo"
15-
icon="i-material-symbols-redo"
16-
color="white"
17-
class="disabled:text-gray-500"
18-
@click="redo"
19-
/>
6+
<UTooltip text="Undo" :shortcuts="undoShortcut" :popper="{ placement: 'left' }">
7+
<UButton
8+
:disabled="!canUndo"
9+
color="white"
10+
icon="i-material-symbols-undo"
11+
class="disabled:text-gray-500"
12+
@click="undo"
13+
/>
14+
</UTooltip>
15+
<UTooltip text="Redo" :shortcuts="redoShortcut" :popper="{ placement: 'right' }">
16+
<UButton
17+
:disabled="!canRedo"
18+
icon="i-material-symbols-redo"
19+
color="white"
20+
class="disabled:text-gray-500"
21+
@click="redo"
22+
/>
23+
</UTooltip>
2024
</UButtonGroup>
2125
</template>
2226

@@ -26,7 +30,44 @@ const workingFormStore = useWorkingFormStore()
2630
const { undo, redo, clearHistory } = workingFormStore
2731
const { canUndo, canRedo } = storeToRefs(workingFormStore)
2832
33+
defineShortcuts({
34+
meta_z: {
35+
whenever: [canUndo],
36+
handler: () => {
37+
undo()
38+
}
39+
},
40+
meta_shift_z: {
41+
whenever: [canRedo],
42+
handler: () => {
43+
redo()
44+
}
45+
}
46+
})
47+
48+
const undoShortcut = computed(() => {
49+
return getOS() == 'macOS' ? ['', 'Z'] : ['Ctrl', 'Z']
50+
})
51+
52+
const redoShortcut = computed(() => {
53+
return getOS() == 'macOS' ? ['', 'Shift', 'Z'] : ['Ctrl', 'Shift', 'Z']
54+
})
55+
2956
onMounted(() => {
3057
setTimeout(() => { clearHistory() }, 500)
3158
})
59+
60+
const getOS = ()=> {
61+
if (navigator.userAgentData) {
62+
// Modern method
63+
return navigator.userAgentData.platform;
64+
} else {
65+
// Fallback for older browsers
66+
const userAgent = navigator.userAgent.toLowerCase();
67+
if (userAgent.indexOf("mac") > -1) return "macOS";
68+
if (userAgent.indexOf("win") > -1) return "Windows";
69+
if (userAgent.indexOf("linux") > -1) return "Linux";
70+
return "Unknown";
71+
}
72+
}
3273
</script>

0 commit comments

Comments
 (0)