Fdcde undo/redo upgrade (#475)

* fix password reset bug

* implement popover and keyboard shortcuts
This commit is contained in:
Favour Olayinka 2024-07-02 14:15:59 +01:00 committed by GitHub
parent 52f65752af
commit 383fff7b2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 55 additions and 14 deletions

View File

@ -3,20 +3,24 @@
size="sm" size="sm"
orientation="horizontal" orientation="horizontal"
> >
<UButton <UTooltip text="Undo" :shortcuts="undoShortcut" :popper="{ placement: 'left' }">
:disabled="!canUndo" <UButton
color="white" :disabled="!canUndo"
icon="i-material-symbols-undo" color="white"
class="disabled:text-gray-500" icon="i-material-symbols-undo"
@click="undo" class="disabled:text-gray-500"
/> @click="undo"
<UButton />
:disabled="!canRedo" </UTooltip>
icon="i-material-symbols-redo" <UTooltip text="Redo" :shortcuts="redoShortcut" :popper="{ placement: 'right' }">
color="white" <UButton
class="disabled:text-gray-500" :disabled="!canRedo"
@click="redo" icon="i-material-symbols-redo"
/> color="white"
class="disabled:text-gray-500"
@click="redo"
/>
</UTooltip>
</UButtonGroup> </UButtonGroup>
</template> </template>
@ -26,7 +30,44 @@ const workingFormStore = useWorkingFormStore()
const { undo, redo, clearHistory } = workingFormStore const { undo, redo, clearHistory } = workingFormStore
const { canUndo, canRedo } = storeToRefs(workingFormStore) const { canUndo, canRedo } = storeToRefs(workingFormStore)
defineShortcuts({
meta_z: {
whenever: [canUndo],
handler: () => {
undo()
}
},
meta_shift_z: {
whenever: [canRedo],
handler: () => {
redo()
}
}
})
const undoShortcut = computed(() => {
return getOS() == 'macOS' ? ['⌘', 'Z'] : ['Ctrl', 'Z']
})
const redoShortcut = computed(() => {
return getOS() == 'macOS' ? ['⌘', 'Shift', 'Z'] : ['Ctrl', 'Shift', 'Z']
})
onMounted(() => { onMounted(() => {
setTimeout(() => { clearHistory() }, 500) setTimeout(() => { clearHistory() }, 500)
}) })
const getOS = ()=> {
if (navigator.userAgentData) {
// Modern method
return navigator.userAgentData.platform;
} else {
// Fallback for older browsers
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf("mac") > -1) return "macOS";
if (userAgent.indexOf("win") > -1) return "Windows";
if (userAgent.indexOf("linux") > -1) return "Linux";
return "Unknown";
}
}
</script> </script>