Skip to content

Commit

Permalink
Remove getPoints()
Browse files Browse the repository at this point in the history
  • Loading branch information
iddan committed Jul 14, 2023
1 parent bea3c85 commit eb42649
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/Spreadsheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ const Spreadsheet = <CellType extends Types.CellBase>(
}

if (state.selected !== prevState.selected) {
const points = state.selected.getPoints(state.model.data);
onSelect(points);
const selectedRange = state.selected.toRange(state.model.data);
const selectedPoints = Array.from(selectedRange || []);
onSelect(selectedPoints);
}

if (state.mode !== prevState.mode) {
Expand Down
23 changes: 11 additions & 12 deletions src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,20 @@ function clear(state: Types.StoreState): Types.StoreState {
return Object.assign({}, cell, { value: undefined });
};

const selectedPoints = state.selected.getPoints(state.model.data);
const selectedRange = state.selected.toRange(state.model.data);

const changes = selectedPoints.map((point) => {
const changes: Types.CommitChanges = [];
let newData = state.model.data;

for (const point of selectedRange || []) {
const cell = Matrix.get(point, state.model.data);
return {
...state,
const clearedCell = clearCell(cell);
changes.push({
prevCell: cell || null,
nextCell: clearCell(cell) || null,
};
});

const newData = selectedPoints.reduce((acc, point) => {
const cell = Matrix.get(point, acc);
return Matrix.set(point, clearCell(cell), acc);
}, state.model.data);
nextCell: clearedCell || null,
});
newData = Matrix.set(point, clearedCell, newData);
}

return {
...state,
Expand Down
16 changes: 0 additions & 16 deletions src/selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,6 @@ describe("RangeSelection.normalizeTo()", () => {
});
});

describe("Selection.prototype.getPoints()", () => {
const cases: Array<
[name: string, selection: Selection, expected: Point.Point[]]
> = [
["Returns empty for non-range", new EmptySelection(), []],
[
"Returns points for range",
new RangeSelection(new PointRange(Point.ORIGIN, Point.ORIGIN)),
[Point.ORIGIN],
],
];
test.each(cases)("%s", (name, selected, expected) => {
expect(selected.getPoints(EXAMPLE_DATA)).toEqual(expected);
});
});

describe("Selection.prototype.has()", () => {
const cases: Array<
[name: string, selection: Selection, point: Point.Point, expected: boolean]
Expand Down
5 changes: 0 additions & 5 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export abstract class Selection {
return range !== null && range.has(point);
}

getPoints(data: Matrix.Matrix<unknown>): Point.Point[] {
const range = this.toRange(data);
return range ? Array.from(range) : [];
}

/** Return whether the given row is entirely selected in given selection */
hasEntireRow(row: number): boolean {
return false;
Expand Down

0 comments on commit eb42649

Please sign in to comment.