diff options
Diffstat (limited to 'web/src/components/grid/selection.ts')
| -rw-r--r-- | web/src/components/grid/selection.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/web/src/components/grid/selection.ts b/web/src/components/grid/selection.ts new file mode 100644 index 0000000..a24bbf5 --- /dev/null +++ b/web/src/components/grid/selection.ts @@ -0,0 +1,23 @@ +import { CellRef, cellRefEquals } from "../../types"; + +export type CellRange = [start: CellRef, end: CellRef]; + +export interface GridSelection { + activeCellRef: CellRef; + range?: CellRange; +} + +export function extendSelection( + selection: GridSelection | undefined, + cellRef: CellRef, +): GridSelection { + if (!selection || cellRefEquals(selection.activeCellRef, cellRef)) { + return { activeCellRef: cellRef }; + } + + if (selection.range) { + return { ...selection, range: [selection.range[0], cellRef] }; + } + + return { ...selection, range: [selection.activeCellRef, cellRef] }; +} |
