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

Handle shift modifier to add/subtract selected cells. #156

Merged
merged 1 commit into from
May 23, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/DataCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var DataCell = function (_PureComponent) {
cell = _props2.cell;

if (!cell.disableEvents) {
onMouseDown(row, col);
onMouseDown(row, col, e);
}
}
}, {
Expand Down
24 changes: 20 additions & 4 deletions lib/DataSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,23 @@ var DataSheet = function (_PureComponent) {

if (offsets && (offsets.i || offsets.j)) {
var _getState6 = this.getState(),
start = _getState6.start;
start = _getState6.start,
end = _getState6.end;

var data = this.props.data;

var oldStartLocation = { i: start.i, j: start.j };
var newEndLocation = { i: end.i + offsets.i, j: end.j + offsets.j };

var newLocation = { i: start.i + offsets.i, j: start.j + offsets.j };

var updateLocation = function updateLocation() {
if (data[newLocation.i] && typeof data[newLocation.i][newLocation.j] !== 'undefined') {
_this3._setState({ start: newLocation, end: newLocation, editing: {} });
_this3._setState({
start: e.shiftKey && !jumpRow ? oldStartLocation : newLocation,
end: e.shiftKey && !jumpRow ? newEndLocation : newLocation,
editing: {}
});
e.preventDefault();
return true;
}
Expand Down Expand Up @@ -515,9 +524,16 @@ var DataSheet = function (_PureComponent) {
}
}, {
key: 'onMouseDown',
value: function onMouseDown(i, j) {
value: function onMouseDown(i, j, e) {
var editing = isEmpty(this.state.editing) || this.state.editing.i !== i || this.state.editing.j !== j ? {} : this.state.editing;
this._setState({ selecting: true, start: { i: i, j: j }, end: { i: i, j: j }, editing: editing, forceEdit: false });

this._setState({
selecting: true,
start: e.shiftKey ? this.state.start : { i: i, j: j },
end: { i: i, j: j },
editing: editing,
forceEdit: false
});

// Keep listening to mouse if user releases the mouse (dragging outside)
document.addEventListener('mouseup', this.onMouseUp);
Expand Down
2 changes: 1 addition & 1 deletion src/DataCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class DataCell extends PureComponent {
handleMouseDown (e) {
const {row, col, onMouseDown, cell} = this.props
if (!cell.disableEvents) {
onMouseDown(row, col)
onMouseDown(row, col, e)
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/DataSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,20 @@ export default class DataSheet extends PureComponent {

handleNavigate (e, offsets, jumpRow) {
if (offsets && (offsets.i || offsets.j)) {
const {start} = this.getState()
const {start, end} = this.getState()
const {data} = this.props
const oldStartLocation = {i: start.i, j: start.j}
const newEndLocation = {i: end.i + offsets.i, j: end.j + offsets.j}

let newLocation = {i: start.i + offsets.i, j: start.j + offsets.j}

const updateLocation = () => {
if (data[newLocation.i] && typeof (data[newLocation.i][newLocation.j]) !== 'undefined') {
this._setState({start: newLocation, end: newLocation, editing: {}})
this._setState({
start: e.shiftKey && !jumpRow ? oldStartLocation : newLocation,
end: e.shiftKey && !jumpRow ? newEndLocation : newLocation,
editing: {}
})
e.preventDefault()
return true
}
Expand Down Expand Up @@ -385,10 +393,17 @@ export default class DataSheet extends PureComponent {
}
}

onMouseDown (i, j) {
onMouseDown (i, j, e) {
let editing = (isEmpty(this.state.editing) || this.state.editing.i !== i || this.state.editing.j !== j)
? {} : this.state.editing
this._setState({selecting: true, start: {i, j}, end: {i, j}, editing: editing, forceEdit: false})

this._setState({
selecting: true,
start: e.shiftKey ? this.state.start : {i, j},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of this.state.start ignores the controlled version of selection.

end: {i, j},
editing: editing,
forceEdit: false
})

// Keep listening to mouse if user releases the mouse (dragging outside)
document.addEventListener('mouseup', this.onMouseUp)
Expand Down