Skip to content

Commit

Permalink
fix: revamp all cell selection range with key combos, fixes #935
Browse files Browse the repository at this point in the history
the previous key combo were incorrect, the new combo is the following
- `Shift+Home` will select from left most (index 0) to current cell position horizontally
- `Shift+End` will select from current cell position until the last cell horizontally
- `Ctrl+Shift+Home` will select everything that is on the left side of current cell position and everything on top current position (horizontally left until first cell & vertically left until first row)
- `Ctrl+Shift+End` will select everything that is on the right side of current cell position and everything on bottom current position (horizontally right until last cell & vertically right until last row)
  • Loading branch information
ghiscoding-SE committed Dec 2, 2023
1 parent 251c91e commit 08e0ecc
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/plugins/slick.cellselectionmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,16 @@ export class SlickCellSelectionModel {

protected handleKeyDown(e: KeyboardEvent) {
let ranges: SlickRange_[], last: SlickRange_;
const colLn = this._grid.getColumns().length;
const active = this._grid.getActiveCell();
const metaKey = e.ctrlKey || e.metaKey;
let dataLn = 0;
if (this._dataView) {
dataLn = this._dataView?.getPagingInfo().pageSize || this._dataView.getLength();
} else {
dataLn = this._grid.getDataLength();
}

if (active && e.shiftKey && !metaKey && !e.altKey && this.isKeyAllowed(e.key)) {

if (active && (e.shiftKey || e.ctrlKey) && !e.altKey && this.isKeyAllowed(e.key)) {
ranges = this.getSelectedRanges().slice();
if (!ranges.length) {
ranges.push(new SlickRange(active.row, active.cell));
Expand All @@ -184,9 +183,10 @@ export class SlickCellSelectionModel {
const dirRow = active.row === last.fromRow ? 1 : -1;
const dirCell = active.cell === last.fromCell ? 1 : -1;
const isSingleKeyMove = e.key.startsWith('Arrow');
let toCell: undefined | number = undefined;
let toRow = 0;

if (isSingleKeyMove) {
if (isSingleKeyMove && !e.ctrlKey) {
// single cell move: (Arrow{Up/ArrowDown/ArrowLeft/ArrowRight})
if (e.key === 'ArrowLeft') {
dCell -= dirCell;
Expand All @@ -207,9 +207,17 @@ export class SlickCellSelectionModel {
this._prevSelectedRow = active.row;
}

if (e.key === 'Home') {
if (e.shiftKey && !e.ctrlKey && e.key === 'Home') {
toCell = 0;
toRow = active.row;
} else if (e.shiftKey && !e.ctrlKey && e.key === 'End') {
toCell = colLn - 1;
toRow = active.row;
} else if (e.ctrlKey && e.shiftKey && e.key === 'Home') {
toCell = 0;
toRow = 0;
} else if (e.key === 'End') {
} else if (e.ctrlKey && e.shiftKey && e.key === 'End') {
toCell = colLn - 1;
toRow = dataLn - 1;
} else if (e.key === 'PageUp') {
if (this._prevSelectedRow >= 0) {
Expand All @@ -230,7 +238,8 @@ export class SlickCellSelectionModel {
}

// define new selection range
const new_last = new SlickRange(active.row, active.cell, toRow, active.cell + dirCell * dCell);
toCell ??= active.cell + dirCell * dCell;
const new_last = new SlickRange(active.row, active.cell, toRow, toCell);
if (this.removeInvalidRanges([new_last]).length) {
ranges.push(new_last);
const viewRow = dirRow > 0 ? new_last.toRow : new_last.fromRow;
Expand Down

0 comments on commit 08e0ecc

Please sign in to comment.