mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-23 22:12:19 +03:00
chore: clean up range selection handler
This commit is contained in:
parent
e89d029bb7
commit
77f320fdba
@ -268,25 +268,11 @@ export default class DataView extends React.Component {
|
||||
|
||||
let i = e.target.name;
|
||||
if (this.state.isShiftDown && this.state.lastSelectedItemIndex !== i) {
|
||||
const start = Math.min(i, this.state.lastSelectedItemIndex);
|
||||
const stop = Math.max(i, this.state.lastSelectedItemIndex) + 1;
|
||||
|
||||
let rangeSelected = {};
|
||||
|
||||
if (checked[i]) {
|
||||
for (let i = start; i < stop; i++) {
|
||||
delete checked[i];
|
||||
}
|
||||
} else {
|
||||
for (let i = start; i < stop; i++) {
|
||||
rangeSelected[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
let newSelection = Object.assign({}, checked, rangeSelected);
|
||||
this.setState({ checked: newSelection, lastSelectedItemIndex: i });
|
||||
|
||||
return;
|
||||
return this._handleShiftClick({
|
||||
currentSelectedItemIndex: i,
|
||||
lastSelectedItemIndex: this.state.lastSelectedItemIndex,
|
||||
checked,
|
||||
});
|
||||
}
|
||||
|
||||
if (e.target.value === false) {
|
||||
@ -333,25 +319,11 @@ export default class DataView extends React.Component {
|
||||
|
||||
let checked = this.state.checked;
|
||||
if (this.state.isShiftDown && this.state.lastSelectedItemIndex !== i) {
|
||||
const start = Math.min(i, this.state.lastSelectedItemIndex);
|
||||
const stop = Math.max(i, this.state.lastSelectedItemIndex) + 1;
|
||||
|
||||
let rangeSelected = {};
|
||||
|
||||
if (checked[i]) {
|
||||
for (let i = start; i < stop; i++) {
|
||||
delete checked[i];
|
||||
}
|
||||
} else {
|
||||
for (let i = start; i < stop; i++) {
|
||||
rangeSelected[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
let newSelection = Object.assign({}, checked, rangeSelected);
|
||||
this.setState({ checked: newSelection, lastSelectedItemIndex: i });
|
||||
|
||||
return;
|
||||
return this._handleShiftClick({
|
||||
currentSelectedItemIndex: i,
|
||||
lastSelectedItemIndex: this.state.lastSelectedItemIndex,
|
||||
checked,
|
||||
});
|
||||
}
|
||||
|
||||
if (checked[i]) {
|
||||
@ -362,6 +334,26 @@ export default class DataView extends React.Component {
|
||||
this.setState({ checked, lastSelectedItemIndex: i });
|
||||
};
|
||||
|
||||
_handleShiftClick = ({ currentSelectedItemIndex, lastSelectedItemIndex, checked }) => {
|
||||
const start = Math.min(currentSelectedItemIndex, lastSelectedItemIndex);
|
||||
const stop = Math.max(currentSelectedItemIndex, lastSelectedItemIndex) + 1;
|
||||
|
||||
let rangeSelected = {};
|
||||
|
||||
for (let i = start; i < stop; i++) {
|
||||
if (checked[currentSelectedItemIndex]) {
|
||||
delete checked[i];
|
||||
} else {
|
||||
rangeSelected[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
let newSelection = Object.assign({}, checked, rangeSelected);
|
||||
this.setState({ checked: newSelection, lastSelectedItemIndex: currentSelectedItemIndex });
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
_handleDelete = async (cid, id) => {
|
||||
const message = `Are you sure you want to delete these files? They will be deleted from your slates as well`;
|
||||
if (!window.confirm(message)) {
|
||||
|
Loading…
Reference in New Issue
Block a user