From 715996aceb4d4dc96410464f60727b98a289be08 Mon Sep 17 00:00:00 2001 From: Josh Kingsley Date: Thu, 30 Oct 2025 13:25:02 +0200 Subject: refactor(web): move selection code --- web/src/components/grid/selection.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 web/src/components/grid/selection.ts (limited to 'web/src/components/grid/selection.ts') 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] }; +} -- cgit v1.2.3