aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/components/FileEntry.vue
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2023-04-11 13:56:10 +0200
committerGitHub <noreply@github.com>2023-04-11 13:56:10 +0200
commita05176a1f592d06b24725cd158baaf85e4456c6d (patch)
treec74eb30753c08662ebab40185e882f54e15eee42 /apps/files/src/components/FileEntry.vue
parentc6645cbc46291d2621992b7f0bb087f115e849eb (diff)
parent8bef77235f4dc23df0e0f0feb959e69d1693d9be (diff)
downloadnextcloud-server-a05176a1f592d06b24725cd158baaf85e4456c6d.tar.gz
nextcloud-server-a05176a1f592d06b24725cd158baaf85e4456c6d.zip
Merge pull request #37639 from nextcloud/feat/files/selection
Diffstat (limited to 'apps/files/src/components/FileEntry.vue')
-rw-r--r--apps/files/src/components/FileEntry.vue57
1 files changed, 45 insertions, 12 deletions
diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue
index fca83cabbd1..eb6ad9f7e18 100644
--- a/apps/files/src/components/FileEntry.vue
+++ b/apps/files/src/components/FileEntry.vue
@@ -25,9 +25,10 @@
<td class="files-list__row-checkbox">
<NcCheckboxRadioSwitch v-if="active"
:aria-label="t('files', 'Select the row for {displayName}', { displayName })"
- :checked.sync="selectedFiles"
- :value="fileid.toString()"
- name="selectedFiles" />
+ :checked="selectedFiles"
+ :value="fileid"
+ name="selectedFiles"
+ @update:checked="onSelectionChange" />
</td>
<!-- Link to file -->
@@ -120,6 +121,7 @@ import { getFileActions } from '../services/FileAction.ts'
import { useFilesStore } from '../store/files.ts'
import { useSelectionStore } from '../store/selection.ts'
import { useUserConfigStore } from '../store/userconfig.ts'
+import { useKeyboardStore } from '../store/keyboard.ts'
import CustomElementRender from './CustomElementRender.vue'
import CustomSvgIconRender from './CustomSvgIconRender.vue'
import logger from '../logger.js'
@@ -159,16 +161,22 @@ export default Vue.extend({
type: Number,
required: true,
},
+ nodes: {
+ type: Array,
+ required: true,
+ },
},
setup() {
const filesStore = useFilesStore()
const selectionStore = useSelectionStore()
const userConfigStore = useUserConfigStore()
+ const keyboardStore = useKeyboardStore()
return {
filesStore,
selectionStore,
userConfigStore,
+ keyboardStore,
}
},
@@ -199,7 +207,7 @@ export default Vue.extend({
},
fileid() {
- return this.source.attributes.fileid
+ return this.source?.fileid?.toString?.()
},
displayName() {
return this.source.attributes.displayName
@@ -242,14 +250,8 @@ export default Vue.extend({
}
},
- selectedFiles: {
- get() {
- return this.selectionStore.selected
- },
- set(selection) {
- logger.debug('Changed nodes selection', { selection })
- this.selectionStore.set(selection)
- },
+ selectedFiles() {
+ return this.selectionStore.selected
},
cropPreviews() {
@@ -454,6 +456,37 @@ export default Vue.extend({
}
},
+ onSelectionChange(selection) {
+ 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
+ }
+
+ logger.debug('Updating selection', { selection })
+ this.selectionStore.set(selection)
+ this.selectionStore.setLastIndex(newSelectedIndex)
+ },
+
t: translate,
formatFileSize,
},