diff options
| author | Josh Kingsley <josh@joshkingsley.me> | 2025-10-26 18:31:23 +0200 |
|---|---|---|
| committer | Josh Kingsley <josh@joshkingsley.me> | 2025-10-26 18:31:23 +0200 |
| commit | a984c69e3cca4bcf822989bb78a8befe2397e487 (patch) | |
| tree | b7599295851dcc87a89e696f32cdc211e77eab18 /web/src/selection.ts | |
| parent | 6ae3218e2dd130c085074a0d13d156bdba99716f (diff) | |
feat(web): draw selection
Diffstat (limited to 'web/src/selection.ts')
| -rw-r--r-- | web/src/selection.ts | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/web/src/selection.ts b/web/src/selection.ts index 88d394b..3d18417 100644 --- a/web/src/selection.ts +++ b/web/src/selection.ts @@ -1,4 +1,4 @@ -import { CellRef } from "./types"; +import { CellRef, cellRefEquals } from "./types"; export abstract class Selection { readonly gridId: string; @@ -8,12 +8,45 @@ export abstract class Selection { this.gridId = gridId; this.activeCellRef = activeCellRef; } + + abstract extend(cellRef: CellRef): Selection; +} + +export class ActiveCellSelection extends Selection { + extend(cellRef: CellRef): Selection { + if (cellRefEquals(cellRef, this.activeCellRef)) { + return this; + } + + return new RangeSelection(this.gridId, this.activeCellRef, [ + this.activeCellRef, + cellRef, + ]); + } } -export class ActiveCellSelection extends Selection {} +export type CellRange = [CellRef, CellRef]; -export class RangeSelection extends Selection {} +export class RangeSelection extends Selection { + #range: CellRange; -export class AllSelection extends Selection {} + get range() { + return this.#range; + } -export class PendingSelection extends Selection {} + constructor(gridId: string, activeCellRef: CellRef, range: CellRange) { + super(gridId, activeCellRef); + this.#range = range; + } + + extend(cellRef: CellRef): Selection { + if (cellRefEquals(cellRef, this.activeCellRef)) { + return new ActiveCellSelection(this.gridId, cellRef); + } + + return new RangeSelection(this.gridId, this.activeCellRef, [ + this.#range[0], + cellRef, + ]); + } +} |
