Skip to content

Commit

Permalink
Revert "Ctrl + Shift + v added shortcut."
Browse files Browse the repository at this point in the history
This reverts commit 1a3ed7a.
  • Loading branch information
bosskmk committed Mar 16, 2022
1 parent e9684a0 commit 447d195
Show file tree
Hide file tree
Showing 21 changed files with 232 additions and 580 deletions.
101 changes: 1 addition & 100 deletions demo/lib/screen/feature/copy_and_paste_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _CopyAndPasteScreenState extends State<CopyAndPasteScreen> {
),
]);

rows.addAll(DummyData.rowsByColumns(length: 5, columns: columns));
rows.addAll(DummyData.rowsByColumns(length: 30, columns: columns));
}

@override
Expand All @@ -62,13 +62,6 @@ class _CopyAndPasteScreenState extends State<CopyAndPasteScreen> {
topContents: const [
Text(
'Copy and paste are operated depending on the cell and row selection status.'),
Text('Tap and hold a cell and move it to select a row or cell.'),
Text('Ctrl + a : Select an entire row or cell.'),
Text(
'Ctrl + c : Copies the currently selected row or cell to the clipboard.'),
Text('Ctrl + v : Paste the copied text array into the cell.'),
Text(
'Ctrl + Shift + v : If the copied text array is larger than the line at the currently selected position, a new line is added.'),
],
topButtons: [
PlutoExampleButton(
Expand All @@ -82,98 +75,6 @@ class _CopyAndPasteScreenState extends State<CopyAndPasteScreen> {
onChanged: (PlutoGridOnChangedEvent event) {
print(event);
},
createHeader: (stateManager) {
return _Header(stateManager: stateManager);
},
),
);
}
}

class _Header extends StatefulWidget {
final PlutoGridStateManager stateManager;

const _Header({
required this.stateManager,
Key? key,
}) : super(key: key);

@override
_HeaderState createState() => _HeaderState();
}

class _HeaderState extends State<_Header> {
PlutoGridSelectingMode gridSelectingMode = PlutoGridSelectingMode.row;

@override
void initState() {
super.initState();

widget.stateManager.setSelectingMode(gridSelectingMode);
}

void setGridSelectingMode(PlutoGridSelectingMode? mode) {
if (gridSelectingMode == mode || mode == null) {
return;
}

setState(() {
gridSelectingMode = mode;
widget.stateManager.setSelectingMode(mode);
});
}

void handleAddDummyRow() {
widget.stateManager.appendRows(
[DummyData.rowByColumns(widget.stateManager.refColumns)],
);
}

void handleRemoveSelectedRowsButton() {
widget.stateManager.removeRows(widget.stateManager.currentSelectingRows);
}

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Wrap(
spacing: 10,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
DropdownButtonHideUnderline(
child: DropdownButton(
value: gridSelectingMode,
items: PlutoGridStateManager.selectingModes
.map<DropdownMenuItem<PlutoGridSelectingMode>>(
(PlutoGridSelectingMode item) {
final color = gridSelectingMode == item ? Colors.blue : null;

return DropdownMenuItem<PlutoGridSelectingMode>(
value: item,
child: Text(
item.toShortString(),
style: TextStyle(color: color),
),
);
}).toList(),
onChanged: (PlutoGridSelectingMode? mode) {
setGridSelectingMode(mode);
},
),
),
ElevatedButton(
child: const Text('Add dummy row'),
onPressed: handleAddDummyRow,
),
ElevatedButton(
child: const Text('Remove Selected Rows'),
onPressed: handleRemoveSelectedRowsButton,
),
],
),
),
);
}
Expand Down
1 change: 0 additions & 1 deletion demo/lib/screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ class PlutoFeatures extends StatelessWidget {
onTapLiveDemo: () {
Navigator.pushNamed(context, CopyAndPasteScreen.routeName);
},
trailing: updateIcon,
),
PlutoListTile(
title: 'Moving',
Expand Down
13 changes: 6 additions & 7 deletions lib/src/helper/pluto_key_manager_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,18 @@ extension PlutoKeyManagerEventExtention on PlutoKeyManagerEvent {
bool get isCharacter => characters.contains(event.logicalKey.keyId);

bool get isCtrlC {
return isCtrlPressed && event.logicalKey.keyLabel == 'C';
return isCtrlPressed &&
event.logicalKey.keyId == LogicalKeyboardKey.keyC.keyId;
}

bool get isCtrlV {
return isCtrlPressed && !isShiftPressed && event.logicalKey.keyLabel == 'V';
}

bool get isCtrlShiftV {
return isCtrlPressed && isShiftPressed && event.logicalKey.keyLabel == 'V';
return isCtrlPressed &&
event.logicalKey.keyId == LogicalKeyboardKey.keyV.keyId;
}

bool get isCtrlA {
return isCtrlPressed && event.logicalKey.keyLabel == 'A';
return isCtrlPressed &&
event.logicalKey.keyId == LogicalKeyboardKey.keyA.keyId;
}

bool get isShiftPressed {
Expand Down
18 changes: 0 additions & 18 deletions lib/src/manager/pluto_grid_key_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ class PlutoGridKeyManager {
return;
}

if (keyEvent.isCtrlShiftV) {
_handleCtrlShiftV(keyEvent);
return;
}

if (keyEvent.isCtrlA) {
_handleCtrlA(keyEvent);
return;
Expand Down Expand Up @@ -363,19 +358,6 @@ class PlutoGridKeyManager {
});
}

void _handleCtrlShiftV(PlutoKeyManagerEvent keyEvent) {
if (stateManager.isEditing == true) {
return;
}

Clipboard.getData('text/plain').then((value) {
List<List<String>> textList =
PlutoClipboardTransformation.stringToList(value!.text!);

stateManager.pasteCellValueWithAppendingRows(textList);
});
}

void _handleCtrlA(PlutoKeyManagerEvent keyEvent) {
if (stateManager.isEditing == true) {
return;
Expand Down
25 changes: 0 additions & 25 deletions lib/src/manager/state/editing_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ abstract class IEditingState {
/// Paste based on current cell
void pasteCellValue(List<List<String>> textList);

/// When pasting cells,
/// if the number of rows in textList is greater than the current rows, new rows are added.
void pasteCellValueWithAppendingRows(List<List<String>> textList);

/// Cast the value according to the column type.
dynamic castValueByColumnType(dynamic value, PlutoColumn column);

Expand Down Expand Up @@ -163,27 +159,6 @@ mixin EditingState implements IPlutoGridState {
notifyListeners();
}

@override
void pasteCellValueWithAppendingRows(List<List<String>> textList) {
int countExistingRows = refRows.length;

if (currentCellPosition != null) {
countExistingRows -= currentCellPosition!.rowIdx!;
}

int countAddingRows = textList.length - countExistingRows;

if (countAddingRows > 0) {
appendNewRows(count: countAddingRows, notify: false);
}

if (currentCellPosition == null) {
setCurrentCell(firstCell, 0, notify: false);
}

pasteCellValue(textList);
}

@override
dynamic castValueByColumnType(dynamic value, PlutoColumn column) {
if (column.type.isNumber) {
Expand Down
69 changes: 15 additions & 54 deletions lib/src/manager/state/row_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,23 @@ abstract class IRowState {
bool notify = true,
});

void insertRows(
int rowIdx,
List<PlutoRow> rows, {
bool notify = true,
});
void insertRows(int rowIdx, List<PlutoRow> rows);

void prependNewRows({
int count = 1,
bool notify = true,
});

void prependRows(
List<PlutoRow> rows, {
bool notify = true,
});
void prependRows(List<PlutoRow> rows);

void appendNewRows({
int count = 1,
bool notify = true,
});

void appendRows(
List<PlutoRow> rows, {
bool notify = true,
});
void appendRows(List<PlutoRow> rows);

void removeCurrentRow({
bool notify = true,
});
void removeCurrentRow();

void removeRows(
List<PlutoRow> rows, {
bool notify = true,
});
void removeRows(List<PlutoRow> rows);

void moveRowsByOffset(
List<PlutoRow> rows,
Expand Down Expand Up @@ -254,11 +237,7 @@ mixin RowState implements IPlutoGridState {
}

@override
void insertRows(
int rowIdx,
List<PlutoRow> rows, {
bool notify = true,
}) {
void insertRows(int rowIdx, List<PlutoRow> rows) {
if (rows.isEmpty) {
return;
}
Expand Down Expand Up @@ -315,24 +294,18 @@ mixin RowState implements IPlutoGridState {
);
}

if (notify) {
notifyListeners();
}
notifyListeners();
}

@override
void prependNewRows({
int count = 1,
bool notify = true,
}) {
prependRows(getNewRows(count: count), notify: notify);
prependRows(getNewRows(count: count));
}

@override
void prependRows(
List<PlutoRow> rows, {
bool notify = true,
}) {
void prependRows(List<PlutoRow> rows) {
if (rows.isEmpty) {
return;
}
Expand Down Expand Up @@ -385,24 +358,18 @@ mixin RowState implements IPlutoGridState {
);
}

if (notify) {
notifyListeners();
}
notifyListeners();
}

@override
void appendNewRows({
int count = 1,
bool notify = true,
}) {
appendRows(getNewRows(count: count), notify: notify);
appendRows(getNewRows(count: count));
}

@override
void appendRows(
List<PlutoRow> rows, {
bool notify = true,
}) {
void appendRows(List<PlutoRow> rows) {
if (rows.isEmpty) {
return;
}
Expand All @@ -427,15 +394,11 @@ mixin RowState implements IPlutoGridState {

_insertRows(refRows.length, rows, state: PlutoRowState.added);

if (notify) {
notifyListeners();
}
notifyListeners();
}

@override
void removeCurrentRow({
bool notify = true,
}) {
void removeCurrentRow() {
if (currentRowIdx == null) {
return;
}
Expand All @@ -444,9 +407,7 @@ mixin RowState implements IPlutoGridState {

resetCurrentState(notify: false);

if (notify) {
notifyListeners();
}
notifyListeners();
}

@override
Expand Down
Loading

0 comments on commit 447d195

Please sign in to comment.