Skip to content

Commit

Permalink
feat(files): add default action keyboard shortcut
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Nov 27, 2024
1 parent e38303a commit 4c9ce95
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import FileEntryActions from './FileEntry/FileEntryActions.vue'
import FileEntryCheckbox from './FileEntry/FileEntryCheckbox.vue'
import FileEntryName from './FileEntry/FileEntryName.vue'
import FileEntryPreview from './FileEntry/FileEntryPreview.vue'
import { isDialogOpened } from '../utils/dialogUtils.ts'

export default defineComponent({
name: 'FileEntry',
Expand Down Expand Up @@ -228,8 +229,40 @@ export default defineComponent({
},
},

beforeMount() {
document.addEventListener('keydown', this.onKeyDown)
},

beforeDestroy() {
document.removeEventListener('keydown', this.onKeyDown)
},

methods: {
formatFileSize,

onKeyDown(event: KeyboardEvent) {
// Don't react to the event if a dialog is open
if (isDialogOpened()) {
return
}

// Don't react if ctrl, meta or alt key is pressed, we don't need those here
if (event.ctrlKey || event.altKey || event.metaKey) {
return
}

// Don't react to the event if the file row is not active
if (!this.isActive) {
return
}

// Enter opens the file
if (event.key === 'Enter') {
event.preventDefault()
event.stopPropagation()
this.defaultFileAction?.exec(this.source, this.currentView, this.currentDir)
}
},
},
})
</script>
2 changes: 1 addition & 1 deletion apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default defineComponent({
return
}

// Ignore right click (button & 2) and any auxillary button expect mouse-wheel (button & 4)
// Ignore right click (button & 2) and any auxiliary button expect mouse-wheel (button & 4)
if (Boolean(event.button & 2) || event.button > 4) {
return
}
Expand Down

0 comments on commit 4c9ce95

Please sign in to comment.