add group selection

This commit is contained in:
Sergey Krylov 2022-06-24 10:51:46 +05:00
parent 93b96ad8ff
commit e77b41f8c6
3 changed files with 30 additions and 3 deletions

View File

@ -30,6 +30,7 @@ module.exports = {
"import/prefer-default-export": "off", "import/prefer-default-export": "off",
"no-console": "off", "no-console": "off",
"no-plusplus": "off", "no-plusplus": "off",
"max-len": "off",
}, },
env: { env: {
browser: true, browser: true,

View File

@ -34,7 +34,9 @@ export class Table extends ExcelComponent {
onMousedown(event: MouseEvent) { onMousedown(event: MouseEvent) {
if (isCell(event)) { if (isCell(event)) {
this.selection.select($(event.target as HTMLElement)); if (event.shiftKey) this.selection.selectGroup($(event.target as HTMLElement));
else this.selection.select($(event.target as HTMLElement));
return; return;
} }

View File

@ -1,4 +1,4 @@
import { Dom } from '../../core/dom'; import { $, Dom } from '../../core/dom';
export class TableSelection { export class TableSelection {
static selectedClassName = 'selected'; static selectedClassName = 'selected';
@ -19,7 +19,31 @@ export class TableSelection {
this.group = []; this.group = [];
} }
selectGroup() { selectGroup($el: Dom) {
const startCellParams = this.getParamsFromCellId(this.group[0].data.id);
const selectedCellParams = this.getParamsFromCellId($el.data.id);
const startCol = Math.min(+startCellParams.col, +selectedCellParams.col);
const endCol = Math.max(+startCellParams.col, +selectedCellParams.col);
const startRow = Math.min(+startCellParams.row, +selectedCellParams.row);
const endRow = Math.max(+startCellParams.row, +selectedCellParams.row);
this.clearSelection();
for (let row = startRow; row <= endRow; row++) {
for (let col = startCol; col <= endCol; col++) {
const cell = $(`[data-id="${row}:${col}"]`);
this.group.push(cell);
cell.addClass(TableSelection.selectedClassName);
}
}
}
getParamsFromCellId(cellId: string) {
const row = cellId.split(':')[0];
const col = cellId.split(':')[1];
return { col, row };
} }
} }