From 4c9ce95ba10728930a3156e14ae7b15081af1abd Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Wed, 27 Nov 2024 21:49:56 +0100 Subject: [PATCH] feat(files): add default action keyboard shortcut Signed-off-by: skjnldsv --- apps/files/src/components/FileEntry.vue | 33 +++++++++++++++++++++ apps/files/src/components/FileEntryMixin.ts | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue index 7af76c87c4318..7238daca1f4b8 100644 --- a/apps/files/src/components/FileEntry.vue +++ b/apps/files/src/components/FileEntry.vue @@ -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', @@ -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) + } + }, }, }) diff --git a/apps/files/src/components/FileEntryMixin.ts b/apps/files/src/components/FileEntryMixin.ts index 4a4e4f497b5ec..34336cdf027a1 100644 --- a/apps/files/src/components/FileEntryMixin.ts +++ b/apps/files/src/components/FileEntryMixin.ts @@ -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 }