feat: add v-shortcut directive for keyboard shortcuts #942
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#942
Loading…
Reference in New Issue
No description provided.
Delete Branch "feature/shortcut"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR moves all keyboard shortcuts to the github/hotkey library, adding a light v-directive wrapper around it. This allows us to add shortcuts like
g k
to open the kanban board or switch between list views.@ -758,0 +759,4 @@
},
"list": {
"title": "List Views",
"switchToListView": "Switch to list view",
Use these titles also as title on the links
Done.
@ -14,3 +14,2 @@
class="menu-show-button"
@shortkey="() => $store.commit('toggleMenu')"
v-shortkey="['ctrl', 'e']"
v-shortcut="'Control+e'"
Does this also support
cmd
on mac? That was something that always annoyed me a bit.Speaking for all occasions of
Control
I think that would be
Meta
. Will add it.The full list is here btw: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
I always use https://keycode.info/ =)
I've added a check to switch the shortcuts based on the user agent. Maybe a bit overengeneered, but makes for a great api.
Could you test it? I don't own a mac...
Might be the way to go.
I think you need add iOS to the test aswell (some people use iPads as working device with keyboard attached).
Not sure which method makes most sense. Pick one and I'll test everything together:
https://stackoverflow.com/questions/9038625/detect-if-device-is-ios
Added.
I don't have a keyboard on iOS. Rest seeemed to work on macOS & iOS.
Maybe we should rename the function to
isAppleDevice
to reflect the change.Renamed.
@ -27,0 +34,4 @@
</div>
<p>
<strong>{{ $t('keyboardShortcuts.list.switchToListView') }}</strong>
<shortcut :keys="['g', 'l']" :combination="$t('keyboardShortcuts.then')"/>
This seems a bit error prone to sync the global shortcuts manually.
How about we create some object to save the info that can be accessed from everywhere
But wouldn't the only difference then be that the information about the shortcuts is saved in another file instead of the component directly?
Not just that. There is then one central place where all the shortcuts are defined. This can be handy in the future e.g. if we want to show shortcuts also in the quick command bar.
I think that makes sense. Added.
@ -65,1 +90,4 @@
components: {Shortcut},
computed: {
isTaskPage() {
return this.$route.name === 'task.detail' ||
use an array +
includes
Done!
@ -0,0 +5,4 @@
shortcuts: [
{
title: 'keyboardShortcuts.toggleMenu',
keys: ['ctrl', 'e'],
Since the platform will never change on runtime:
How about putting the logic from
isMac ? k.replace('ctrl', '⌘') : k
in this file (doing it once at the top).Makes sense, changed.
@ -0,0 +4,4 @@
available: () => null,
shortcuts: [
{
title: 'keyboardShortcuts.toggleMenu',
I once had problems with vue-i18n and dynamic keys in production build. Maybe not an issue anymore 🤷♂️
Good hint. Let me check that.
It looks like this is working fine.
@ -0,0 +55,4 @@
},
{
title: 'keyboardShortcuts.task.title',
available: (route) => [
fancy! =)
@ -0,0 +6,4 @@
<div class="message is-primary" v-if="s.available($route) === null">
<div class="message-body">
{{ $t('keyboardShortcuts.allPages') }}
Done.
@ -0,0 +15,4 @@
</div>
</div>
<p v-for="(sc, si) in s.shortcuts" :key="si">
Picky: I just realize this is the perfect usecase for:
<dl>
Probably yeah :)
Added it, hope I understood it correctly.
@dpschen Could you give this another review?
@ -1,10 +1,10 @@
<template>
<span class="shortcuts">
<dd class="shortcuts">
Making the main element of
shortcut.vue
a<dd>
works in this context, but might not in different ones. I think we should add a prop for the tag with the default prop being adiv
.Done.
Ahh interesting. I somehow always thought that
is
is a reserved prop name for vue. But seems like<component>
really is just a component with the propis
that can mount other components =)Branch looks good!
Hi konrad!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://942-featureshortcut--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!