1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

improve multiple selection when hold shift key on list layout (#6640)

This commit is contained in:
Aries
2024-08-29 09:58:15 +08:00
committed by GitHub
parent fedfbf9bf4
commit a3d6d81bc6

View File

@@ -1430,10 +1430,34 @@ class LibContentView extends React.Component {
newSelectedDirentList.push(clickedDirent);
}
} else if (isShiftKeyPressed && lastSelectedIndex !== null) {
// Shift key is pressed: Select all items between the last selected and the clicked item
const rangeStart = Math.min(this.state.lastSelectedIndex, clickedIndex);
const rangeEnd = Math.max(this.state.lastSelectedIndex, clickedIndex);
newSelectedDirentList = direntList.slice(rangeStart, rangeEnd + 1);
// Shift key is pressed: Select or unselect items based on the clicked index
const firstSelectedIndex = direntList.findIndex(dirent => dirent.name === newSelectedDirentList[0].name);
if (clickedIndex < firstSelectedIndex) {
// Selected all the items between the clicked item and the first selected item
const rangeSelectedDirents = direntList.slice(clickedIndex, firstSelectedIndex + 1);
const rangeSelectedNames = new Set(rangeSelectedDirents.map(dirent => dirent.name));
newSelectedDirentList = [
...newSelectedDirentList.filter(dirent => rangeSelectedNames.has(dirent.name)),
...rangeSelectedDirents
];
} else if (clickedIndex >= firstSelectedIndex && clickedIndex < lastSelectedIndex) {
// Unselect items between clicked item and the last selected item
const rangeSelectedDirents = direntList.slice(firstSelectedIndex, clickedIndex + 1);
const rangeSelectedNames = new Set(rangeSelectedDirents.map(dirent => dirent.name));
newSelectedDirentList = newSelectedDirentList.filter(dirent => rangeSelectedNames.has(dirent.name));
} else {
// Select all items between the first selected and the clicked item
const rangeStart = Math.min(firstSelectedIndex, clickedIndex);
const rangeEnd = Math.max(firstSelectedIndex, clickedIndex);
const rangeSelectedDirents = direntList.slice(rangeStart, rangeEnd + 1);
// Merge the new range selection with the existing selection
const rangeSelectedNames = new Set(rangeSelectedDirents.map(dirent => dirent.name));
newSelectedDirentList = [
...newSelectedDirentList.filter(dirent => !rangeSelectedNames.has(dirent.name)),
...rangeSelectedDirents
];
}
} else {
newSelectedDirentList = [clickedDirent];
}