Skip to content

Commit

Permalink
fix(igx-grid): getSelectedRanges inside event handler
Browse files Browse the repository at this point in the history
Fixed a possible error with an empty range when restoring the document
selection

Closes #5135
  • Loading branch information
rkaraivanov committed Jun 21, 2019
1 parent 3b0c3da commit 4f9e6a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions projects/igniteui-angular/src/lib/core/grid-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class IgxGridSelectionService {
selection = new Map<number, Set<number>>();
temp = new Map<number, Set<number>>();
_ranges: Set<string> = new Set<string>();
_selectionRange: Range;
_selectionRange = new Range();


/**
Expand Down Expand Up @@ -474,8 +474,8 @@ export class IgxGridSelectionService {
if (this.pointerState.shift) {
this.clearTextSelection();
this.restoreTextSelection();
emitter.emit(this.generateRange(node, this.pointerState));
this.addRangeMeta(node, this.pointerState);
emitter.emit(this.generateRange(node, this.pointerState));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ describe('IgxGrid - Multi Cell selection', () => {
HelperUtils.verifySelectedRange(grid, 0, 3, 2, 3);
});

it('Should return correct ranges from `getSelectedRanges` on shfit + click in the event handler', () => {
const firstCell = grid.getCellByColumn(3, 'HireDate');
const secondCell = grid.getCellByColumn(1, 'ID');

const sub = grid.onRangeSelection.subscribe(_ => {
expect(grid.selectedCells.length).toEqual(12);
const range = grid.getSelectedRanges()[0];
HelperUtils.verifySelectedRange(grid, range.rowStart, range.rowEnd, range.columnStart, range.columnEnd);
HelperUtils.verifySelectedRange(grid, 1, 3, 0, 3);
});
HelperUtils.selectCellsRangeWithShiftKeyNoWait(fix, firstCell, secondCell);
sub.unsubscribe();
});

it('Should be able to select range with Shift key when first cell is not visible', (async () => {
const firstCell = grid.getCellByColumn(1, 'ID');
const selectionChangeSpy = spyOn<any>(grid.onRangeSelection, 'emit').and.callThrough();
Expand Down

0 comments on commit 4f9e6a3

Please sign in to comment.