summaryrefslogtreecommitdiff
path: root/web/src/selection.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/selection.ts')
-rw-r--r--web/src/selection.ts43
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,
+ ]);
+ }
+}