diff options
| author | Josh Kingsley <josh@joshkingsley.me> | 2025-10-30 13:25:02 +0200 |
|---|---|---|
| committer | Josh Kingsley <josh@joshkingsley.me> | 2025-10-30 13:25:02 +0200 |
| commit | 715996aceb4d4dc96410464f60727b98a289be08 (patch) | |
| tree | 876d97664a22246ebecfc25cad1f4b96dee031a0 /web/src/components/grid/selection.ts | |
| parent | 7ef8366bfc43775bf26e71e77bddf31af829dfde (diff) | |
refactor(web): move selection code
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] }; +} |
