Skip to content

Commit

Permalink
feat: add key shortcuts
Browse files Browse the repository at this point in the history
- 'Ctrl + a' selects all files in listing.
- 'Enter' to confirm a prompt.
  • Loading branch information
ramiresviana committed Jun 21, 2020
1 parent cd454ba commit 95316cb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
15 changes: 14 additions & 1 deletion frontend/src/components/files/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default {
document.removeEventListener('drop', this.drop)
},
methods: {
...mapMutations([ 'updateUser' ]),
...mapMutations([ 'updateUser', 'addSelected' ]),
base64: function (name) {
return window.btoa(unescape(encodeURIComponent(name)))
},
Expand All @@ -213,6 +213,19 @@ export default {
case 'v':
this.paste(event)
break
case 'a':
event.preventDefault()
for (let file of this.items.files) {
if (this.$store.state.selected.indexOf(file.index) === -1) {
this.addSelected(file.index)
}
}
for (let dir of this.items.dirs) {
if (this.$store.state.selected.indexOf(dir.index) === -1) {
this.addSelected(dir.index)
}
}
break
}
},
preventDefault (event) {
Expand Down
29 changes: 28 additions & 1 deletion frontend/src/components/prompts/Prompts.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<component :is="currentComponent"></component>
<component ref="currentComponent" :is="currentComponent"></component>
<div v-show="showOverlay" @click="resetPrompts" class="overlay"></div>
</div>
</template>
Expand Down Expand Up @@ -46,6 +46,33 @@ export default {
}
}
},
created () {
window.addEventListener('keydown', (event) => {
if (this.show == null)
return
let prompt = this.$refs.currentComponent;
// Enter
if (event.keyCode == 13) {
switch (this.show) {
case 'delete':
prompt.submit()
break;
case 'copy':
prompt.copy(event)
break;
case 'move':
prompt.move(event)
break;
case 'replace':
prompt.showConfirm(event)
break;
}
}
})
},
computed: {
...mapState(['show', 'plugins']),
currentComponent: function () {
Expand Down

0 comments on commit 95316cb

Please sign in to comment.