Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Keyboard shift + click selection selects file double #9003

Merged
merged 4 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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