Skip to content

Commit

Permalink
Bugfix: Keyboard shift + click selection selects file double (#9003)
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat authored May 9, 2023
1 parent ccaaa5c commit 72d435b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default defineComponent({
scrollToResource({ id: nextResourceId } as any)
selectionCursor.value = unref(selectionCursor) + 1
}
const handleShiftClickAction = (resource) => {
const handleShiftClickAction = ({ resource, skipTargetSelection }) => {
const parent = document.querySelectorAll(`[data-item-id='${resource.id}']`)[0]
const resourceNodes = Object.values(parent.parentNode.children)
const latestNode = resourceNodes.find(
Expand All @@ -184,6 +184,9 @@ export default defineComponent({
for (let i = minIndex; i <= maxIndex; i++) {
const nodeId = resourceNodes[i].getAttribute('data-item-id')
if (skipTargetSelection && nodeId === resource.id) {
continue
}
store.commit('Files/ADD_FILE_SELECTION', { id: nodeId })
}
store.commit('Files/SET_LATEST_SELECTED_FILE_ID', resource.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
:model-value="isResourceSelected(item)"
:outline="isLatestSelectedItem(item)"
@update:model-value="setSelection($event, item)"
@click.stop="fileClicked([item, $event])"
@click.stop="fileClicked([item, $event, true])"
/>
</template>
<template #name="{ item }">
Expand Down Expand Up @@ -729,6 +729,7 @@ export default defineComponent({
*/
const resource = data[0]
const eventData = data[1]
const skipTargetSelection = data[2] ?? false
const isCheckboxClicked = eventData?.target.getAttribute('type') === 'checkbox'
const contextActionClicked = eventData?.target?.closest('div')?.id === 'oc-files-context-menu'
Expand All @@ -739,7 +740,7 @@ export default defineComponent({
return eventBus.publish('app.files.list.clicked.meta', resource)
}
if (eventData && eventData.shiftKey) {
return eventBus.publish('app.files.list.clicked.shift', resource)
return eventBus.publish('app.files.list.clicked.shift', { resource, skipTargetSelection })
}
if (isCheckboxClicked) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ describe('KeyboardActions', () => {

it('adds the clicked file to the current selection', () => {
const { wrapper, storeOptions } = getWrapper()
wrapper.vm.handleShiftClickAction(mock<Resource>({ id: resourceId }))
wrapper.vm.handleShiftClickAction({
resource: mock<Resource>({ id: resourceId }),
skipTargetSelection: false
})
expect(storeOptions.modules.Files.mutations.ADD_FILE_SELECTION).toHaveBeenCalled()
expect(storeOptions.modules.Files.mutations.SET_LATEST_SELECTED_FILE_ID).toHaveBeenCalled()
})
Expand Down

0 comments on commit 72d435b

Please sign in to comment.