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] }; }