Skip to content

Commit

Permalink
Change the parameter of setCurrentSelectingPosition.
Browse files Browse the repository at this point in the history
  • Loading branch information
bosskmk committed Nov 8, 2020
1 parent e789473 commit a30b417
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 53 deletions.
26 changes: 17 additions & 9 deletions lib/src/manager/state/keyboard_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ mixin KeyboardState implements IPlutoState {
}

setCurrentSelectingPosition(
columnIdx: cellPosition.columnIdx +
(direction.horizontal ? direction.offset : 0),
rowIdx: cellPosition.rowIdx + (direction.vertical ? direction.offset : 0),
cellPosition: PlutoCellPosition(
columnIdx: cellPosition.columnIdx +
(direction.horizontal ? direction.offset : 0),
rowIdx: cellPosition.rowIdx + (direction.vertical ? direction.offset : 0),
),
);

if (direction.horizontal) {
Expand Down Expand Up @@ -291,8 +293,10 @@ mixin KeyboardState implements IPlutoState {
: currentCellPosition.rowIdx;

setCurrentSelectingPosition(
columnIdx: columnIdx,
rowIdx: rowIdx,
cellPosition: PlutoCellPosition(
columnIdx: columnIdx,
rowIdx: rowIdx,
),
notify: notify,
);

Expand Down Expand Up @@ -324,8 +328,10 @@ mixin KeyboardState implements IPlutoState {
final int rowIdx = direction.isUp ? 0 : _rows.length - 1;

setCurrentSelectingPosition(
columnIdx: columnIdx,
rowIdx: rowIdx,
cellPosition: PlutoCellPosition(
columnIdx: columnIdx,
rowIdx: rowIdx,
),
notify: notify,
);

Expand Down Expand Up @@ -354,8 +360,10 @@ mixin KeyboardState implements IPlutoState {
: currentCellPosition.columnIdx;

setCurrentSelectingPosition(
columnIdx: columnIdx,
rowIdx: rowIdx,
cellPosition: PlutoCellPosition(
columnIdx: columnIdx,
rowIdx: rowIdx,
),
);

moveScrollByRow(direction, rowIdx - direction.offset);
Expand Down
12 changes: 8 additions & 4 deletions lib/src/manager/state/row_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ mixin RowState implements IPlutoState {
if (currentSelectingPosition != null &&
rowIdx <= currentSelectingPosition.rowIdx) {
setCurrentSelectingPosition(
columnIdx: currentSelectingPosition.columnIdx,
rowIdx: rows.length + currentSelectingPosition.rowIdx,
cellPosition: PlutoCellPosition(
columnIdx: currentSelectingPosition.columnIdx,
rowIdx: rows.length + currentSelectingPosition.rowIdx,
),
notify: false,
);
}
Expand Down Expand Up @@ -260,8 +262,10 @@ mixin RowState implements IPlutoState {
/// Update currentSelectingPosition
if (currentSelectingPosition != null) {
setCurrentSelectingPosition(
columnIdx: currentSelectingPosition.columnIdx,
rowIdx: rows.length + currentSelectingPosition.rowIdx,
cellPosition: PlutoCellPosition(
columnIdx: currentSelectingPosition.columnIdx,
rowIdx: rows.length + currentSelectingPosition.rowIdx,
),
notify: false,
);
}
Expand Down
35 changes: 22 additions & 13 deletions lib/src/manager/state/selecting_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ abstract class ISelectingState {

/// Sets the position of a multi-selected cell.
void setCurrentSelectingPosition({
int columnIdx,
int rowIdx,
PlutoCellPosition cellPosition,
bool notify = true,
});

Expand Down Expand Up @@ -195,8 +194,10 @@ mixin SelectingState implements IPlutoState {
setCurrentCell(firstCell, 0, notify: false);

setCurrentSelectingPosition(
columnIdx: _columns.length - 1,
rowIdx: _rows.length - 1,
cellPosition: PlutoCellPosition(
columnIdx: _columns.length - 1,
rowIdx: _rows.length - 1,
),
);
break;
case PlutoSelectingMode.Row:
Expand All @@ -218,25 +219,29 @@ mixin SelectingState implements IPlutoState {
}

void setCurrentSelectingPosition({
int columnIdx,
int rowIdx,
PlutoCellPosition cellPosition,
bool notify = true,
}) {
if (_selectingMode.isNone) {
return;
}

final cellPosition =
PlutoCellPosition(columnIdx: columnIdx, rowIdx: rowIdx);
if (_currentSelectingPosition == cellPosition) {
return;
}

if (isInvalidCellPosition(cellPosition)) {
return;
}

_currentSelectingPosition = cellPosition;

if (_selectingMode.isRow) {
setCurrentSelectingRowsByRange(currentRowIdx, rowIdx, notify: false);
if (_currentSelectingPosition != null && _selectingMode.isRow) {
setCurrentSelectingRowsByRange(
currentRowIdx,
_currentSelectingPosition.rowIdx,
notify: false,
);
}

if (notify) {
Expand All @@ -258,8 +263,7 @@ mixin SelectingState implements IPlutoState {
return;
} else {
setCurrentSelectingPosition(
columnIdx: cellPosition.columnIdx,
rowIdx: cellPosition.rowIdx,
cellPosition: cellPosition,
notify: notify,
);
}
Expand Down Expand Up @@ -320,7 +324,12 @@ mixin SelectingState implements IPlutoState {
return;
}

setCurrentSelectingPosition(columnIdx: columnIdx, rowIdx: rowIdx);
setCurrentSelectingPosition(
cellPosition: PlutoCellPosition(
columnIdx: columnIdx,
rowIdx: rowIdx,
),
);
}

void setCurrentSelectingRowsByRange(int from, int to, {notify: true}) {
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widget/cell_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ class _CellWidgetState extends State<CellWidget>
widget.stateManager.columnIndex(widget.column);

widget.stateManager.setCurrentSelectingPosition(
columnIdx: columnIdx, rowIdx: widget.rowIdx);
cellPosition: PlutoCellPosition(
columnIdx: columnIdx,
rowIdx: widget.rowIdx,
),
);
} else if (widget.stateManager.keyPressed.ctrl) {
widget.stateManager.toggleSelectingRow(widget.rowIdx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ void main() {
);

stateManager.setCurrentSelectingPosition(
columnIdx: columnIdxToSelect,
rowIdx: rowIdxToSelect,
cellPosition: PlutoCellPosition(
columnIdx: columnIdxToSelect,
rowIdx: rowIdxToSelect,
),
);
},
),
Expand Down
7 changes: 6 additions & 1 deletion test/src/manager/state/editing_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ void main() {

stateManager.setCurrentCell(currentCell, 2);

stateManager.setCurrentSelectingPosition(columnIdx: 6, rowIdx: 4);
stateManager.setCurrentSelectingPosition(
cellPosition: PlutoCellPosition(
columnIdx: 6,
rowIdx: 4,
),
);

// when
stateManager.pasteCellValue([
Expand Down
34 changes: 27 additions & 7 deletions test/src/manager/state/keyboard_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ void main() {

expect(stateManager.isEditing, isFalse);

stateManager.setCurrentSelectingPosition(columnIdx: 2, rowIdx: 0);
stateManager.setCurrentSelectingPosition(
cellPosition: PlutoCellPosition(
columnIdx: 2,
rowIdx: 0,
),
);

expect(stateManager.currentSelectingPosition, isNotNull);
expect(stateManager.currentSelectingPosition.columnIdx, 2);
Expand Down Expand Up @@ -439,7 +444,12 @@ void main() {

expect(stateManager.isEditing, isFalse);

stateManager.setCurrentSelectingPosition(columnIdx: 2, rowIdx: 0);
stateManager.setCurrentSelectingPosition(
cellPosition: PlutoCellPosition(
columnIdx: 2,
rowIdx: 0,
),
);

expect(stateManager.currentSelectingPosition, isNotNull);
expect(stateManager.currentSelectingPosition.columnIdx, 2);
Expand Down Expand Up @@ -585,7 +595,12 @@ void main() {

expect(stateManager.isEditing, isFalse);

stateManager.setCurrentSelectingPosition(columnIdx: 3, rowIdx: 2);
stateManager.setCurrentSelectingPosition(
cellPosition: PlutoCellPosition(
columnIdx: 3,
rowIdx: 2,
),
);

expect(stateManager.currentSelectingPosition.columnIdx, 3);
expect(stateManager.currentSelectingPosition.rowIdx, 2);
Expand Down Expand Up @@ -635,7 +650,7 @@ void main() {

withColumnAndRows.test(
'rowIdx 가 0 보다 작으면 0번 행이 선택 되어야 한다.',
(tester) async {
(tester) async {
stateManager.setCurrentCell(stateManager.rows[3].cells['column3'], 3);

expect(stateManager.currentCell, isNotNull);
Expand All @@ -652,7 +667,7 @@ void main() {

withColumnAndRows.test(
'rowIdx 가 0 보다 크면 마지막 행이 선택 되어야 한다.',
(tester) async {
(tester) async {
stateManager.setCurrentCell(stateManager.rows[3].cells['column3'], 3);

expect(stateManager.currentCell, isNotNull);
Expand Down Expand Up @@ -686,12 +701,17 @@ void main() {

withColumnAndRows.test(
'선택 된 셀이 있으면 컬럼 위치가 유지되어야 한다.',
(tester) async {
(tester) async {
stateManager.setCurrentCell(stateManager.rows[3].cells['column3'], 0);

expect(stateManager.currentCell, isNotNull);

stateManager.setCurrentSelectingPosition(columnIdx: 5, rowIdx: 3);
stateManager.setCurrentSelectingPosition(
cellPosition: PlutoCellPosition(
columnIdx: 5,
rowIdx: 3,
),
);

expect(stateManager.currentSelectingPosition.columnIdx, 5);
expect(stateManager.currentSelectingPosition.rowIdx, 3);
Expand Down
6 changes: 4 additions & 2 deletions test/src/manager/state/row_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,10 @@ void main() {
final int rowIdxBeforePrependRows = 3;

stateManager.setCurrentSelectingPosition(
columnIdx: 2,
rowIdx: rowIdxBeforePrependRows,
cellPosition: PlutoCellPosition(
columnIdx: 2,
rowIdx: rowIdxBeforePrependRows,
),
);

expect(
Expand Down
Loading

0 comments on commit a30b417

Please sign in to comment.