Skip to content

Commit

Permalink
- Normalize the selection coordinates when switching from row to colu…
Browse files Browse the repository at this point in the history
…mn (or column to row) selection using the SHIFT key. (handsontable#7100)

- Add a test case for the issue.
 �handsontable#7089
  • Loading branch information
jansiegel authored Jul 10, 2020
1 parent 7040dd8 commit 6f3954d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/selection/mouseEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export function mouseDown({ isShiftKey, isLeftClick, isRightClick, coords, selec

} else if (((!selectedCorner && !selectedRow && coords.col < 0) ||
(selectedCorner && coords.col < 0)) && !controller.row) {
selection.selectRows(currentSelection.from.row, coords.row);
selection.selectRows(Math.max(currentSelection.from.row, 0), coords.row);

} else if (((!selectedCorner && !selectedRow && coords.row < 0) ||
(selectedRow && coords.row < 0)) && !controller.column) {
selection.selectColumns(currentSelection.from.col, coords.col);
selection.selectColumns(Math.max(currentSelection.from.col, 0), coords.col);
}

} else {
Expand Down
54 changes: 54 additions & 0 deletions test/e2e/Core_selection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,60 @@ describe('Core_selection', () => {
`).toBeMatchToSelectionPattern();
});

it('should allow switching between row/column selection, when clicking on the headers ' +
'while holding the SHIFT key', () => {
handsontable({
rowHeaders: true,
colHeaders: true,
startRows: 5,
startCols: 5,
});

selectCell(0, 0, 0, 0);

spec().$container.find('.ht_clone_left tr:eq(5) th:eq(0)').simulate('mousedown', { shiftKey: true });
spec().$container.find('.ht_clone_left tr:eq(5) th:eq(0)').simulate('mouseup');

expect(getSelected()).toEqual([[0, -1, 4, 4]]);
expect(`
| ║ - : - : - : - : - |
|===:===:===:===:===:===|
| * ║ A : 0 : 0 : 0 : 0 |
| * ║ 0 : 0 : 0 : 0 : 0 |
| * ║ 0 : 0 : 0 : 0 : 0 |
| * ║ 0 : 0 : 0 : 0 : 0 |
| * ║ 0 : 0 : 0 : 0 : 0 |
`).toBeMatchToSelectionPattern();

spec().$container.find('.ht_clone_top tr:eq(0) th:eq(5)').simulate('mousedown', { shiftKey: true });
spec().$container.find('.ht_clone_top tr:eq(0) th:eq(5)').simulate('mouseup');

expect(getSelected()).toEqual([[-1, 0, 4, 4]]);
expect(`
| ║ * : * : * : * : * |
|===:===:===:===:===:===|
| - ║ A : 0 : 0 : 0 : 0 |
| - ║ 0 : 0 : 0 : 0 : 0 |
| - ║ 0 : 0 : 0 : 0 : 0 |
| - ║ 0 : 0 : 0 : 0 : 0 |
| - ║ 0 : 0 : 0 : 0 : 0 |
`).toBeMatchToSelectionPattern();

spec().$container.find('.ht_clone_left tr:eq(3) th:eq(0)').simulate('mousedown', { shiftKey: true });
spec().$container.find('.ht_clone_left tr:eq(3) th:eq(0)').simulate('mouseup');

expect(getSelected()).toEqual([[0, -1, 2, 4]]);
expect(`
| ║ - : - : - : - : - |
|===:===:===:===:===:===|
| * ║ A : 0 : 0 : 0 : 0 |
| * ║ 0 : 0 : 0 : 0 : 0 |
| * ║ 0 : 0 : 0 : 0 : 0 |
| ║ : : : : |
| ║ : : : : |
`).toBeMatchToSelectionPattern();
});

it('should call onSelection while user selects cells with mouse; onSelectionEnd when user finishes selection', () => {
let tick = 0;
let tickEnd = 0;
Expand Down

0 comments on commit 6f3954d

Please sign in to comment.