From 0f1f73478a59f59d92c4542aa42dc61973c600de Mon Sep 17 00:00:00 2001 From: =?utf8?q?John=20Molakvo=C3=A6?= Date: Thu, 12 Oct 2023 10:05:02 +0200 Subject: [PATCH] fix(files): split FileEntry Checkbox and fix range selection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/files/src/components/FileEntry.vue | 59 +------- .../FileEntry/FileEntryCheckbox.vue | 130 ++++++++++++++++++ 2 files changed, 137 insertions(+), 52 deletions(-) create mode 100644 apps/files/src/components/FileEntry/FileEntryCheckbox.vue diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue index 1a1bf6d9baf..87c36356210 100644 --- a/apps/files/src/components/FileEntry.vue +++ b/apps/files/src/components/FileEntry.vue @@ -37,13 +37,11 @@ - - - - + @@ -177,7 +175,6 @@ import Vue from 'vue' import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js' import NcActions from '@nextcloud/vue/dist/Components/NcActions.js' -import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js' import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js' import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js' @@ -190,10 +187,10 @@ import { hashCode } from '../utils/hashUtils.ts' import { useActionsMenuStore } from '../store/actionsmenu.ts' import { useDragAndDropStore } from '../store/dragging.ts' import { useFilesStore } from '../store/files.ts' -import { useKeyboardStore } from '../store/keyboard.ts' import { useRenamingStore } from '../store/renaming.ts' import { useSelectionStore } from '../store/selection.ts' import CustomElementRender from './CustomElementRender.vue' +import FileEntryCheckbox from './FileEntry/FileEntryCheckbox.vue' import FileEntryPreview from './FileEntry/FileEntryPreview.vue' import logger from '../logger.js' @@ -212,10 +209,10 @@ export default Vue.extend({ FileEntryPreview, NcActionButton, NcActions, - NcCheckboxRadioSwitch, NcIconSvgWrapper, NcLoadingIcon, NcTextField, + FileEntryCheckbox, }, props: { @@ -235,10 +232,6 @@ export default Vue.extend({ type: [Folder, NcFile, Node] as PropType, required: true, }, - index: { - type: Number, - required: true, - }, nodes: { type: Array as PropType, required: true, @@ -253,14 +246,12 @@ export default Vue.extend({ const actionsMenuStore = useActionsMenuStore() const draggingStore = useDragAndDropStore() const filesStore = useFilesStore() - const keyboardStore = useKeyboardStore() const renamingStore = useRenamingStore() const selectionStore = useSelectionStore() return { actionsMenuStore, draggingStore, filesStore, - keyboardStore, renamingStore, selectionStore, } @@ -276,7 +267,6 @@ export default Vue.extend({ }, computed: { - currentView() { return this.$navigation.active }, @@ -600,41 +590,6 @@ export default Vue.extend({ } }, - onSelectionChange(selected: boolean) { - const newSelectedIndex = this.index - const lastSelectedIndex = this.selectionStore.lastSelectedIndex - - // Get the last selected and select all files in between - if (this.keyboardStore?.shiftKey && lastSelectedIndex !== null) { - const isAlreadySelected = this.selectedFiles.includes(this.fileid) - - const start = Math.min(newSelectedIndex, lastSelectedIndex) - const end = Math.max(lastSelectedIndex, newSelectedIndex) - - const lastSelection = this.selectionStore.lastSelection - const filesToSelect = this.nodes - .map(file => file.fileid?.toString?.()) - .slice(start, end + 1) - - // If already selected, update the new selection _without_ the current file - const selection = [...lastSelection, ...filesToSelect] - .filter(fileid => !isAlreadySelected || fileid !== this.fileid) - - logger.debug('Shift key pressed, selecting all files in between', { start, end, filesToSelect, isAlreadySelected }) - // Keep previous lastSelectedIndex to be use for further shift selections - this.selectionStore.set(selection) - return - } - - const selection = selected - ? [...this.selectedFiles, this.fileid] - : this.selectedFiles.filter(fileid => fileid !== this.fileid) - - logger.debug('Updating selection', { selection }) - this.selectionStore.set(selection) - this.selectionStore.setLastIndex(newSelectedIndex) - }, - // Open the actions menu on right click onRightClick(event) { // If already opened, fallback to default browser diff --git a/apps/files/src/components/FileEntry/FileEntryCheckbox.vue b/apps/files/src/components/FileEntry/FileEntryCheckbox.vue new file mode 100644 index 00000000000..376d14d4073 --- /dev/null +++ b/apps/files/src/components/FileEntry/FileEntryCheckbox.vue @@ -0,0 +1,130 @@ + + + + -- 2.39.5