3
3
size =" sm"
4
4
orientation =" horizontal"
5
5
>
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 >
20
24
</UButtonGroup >
21
25
</template >
22
26
@@ -26,7 +30,44 @@ const workingFormStore = useWorkingFormStore()
26
30
const { undo , redo , clearHistory } = workingFormStore
27
31
const { canUndo , canRedo } = storeToRefs (workingFormStore)
28
32
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
+
29
56
onMounted (() => {
30
57
setTimeout (() => { clearHistory () }, 500 )
31
58
})
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
+ }
32
73
</script >
0 commit comments