fix: cross column deletion in the table (#934)
This commit is contained in:
parent
25ee0e5227
commit
432b797914
2 changed files with 148 additions and 0 deletions
|
|
@ -84,6 +84,14 @@ CommandShortcutEventHandler _backspaceInCollapsedSelection = (editorState) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// If the deletion crosses columns and starts from the beginning position
|
||||||
|
// skip the node deletion process
|
||||||
|
// otherwise it will cause an error in table rendering.
|
||||||
|
if (node.parent?.type == TableCellBlockKeys.type &&
|
||||||
|
position.offset == 0) {
|
||||||
|
return KeyEventResult.handled;
|
||||||
|
}
|
||||||
|
|
||||||
Node? tableParent =
|
Node? tableParent =
|
||||||
node.findParent((element) => element.type == TableBlockKeys.type);
|
node.findParent((element) => element.type == TableBlockKeys.type);
|
||||||
Node? prevTableParent;
|
Node? prevTableParent;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
|
import 'package:appflowy_editor/src/editor/block_component/table_block_component/util.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
@ -511,4 +512,143 @@ void main() async {
|
||||||
await editor.dispose();
|
await editor.dispose();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('backspaceCommand - table tests', () {
|
||||||
|
// Before
|
||||||
|
// |Cell in row 1|
|
||||||
|
// 🔽 delete from here
|
||||||
|
// |Cell in row 2|
|
||||||
|
// |Cell in row 3|
|
||||||
|
// After
|
||||||
|
// |Cell in row 1|
|
||||||
|
// |Cell in row 2|
|
||||||
|
// |Cell in row 3|
|
||||||
|
testWidgets('Delete across multiple table rows,', (tester) async {
|
||||||
|
const textRow1 = 'Cell in row 1';
|
||||||
|
const textRow2 = 'Cell in row 2';
|
||||||
|
const textRow3 = 'Cell in row 3';
|
||||||
|
|
||||||
|
final tableNode = TableNode.fromList([
|
||||||
|
[textRow1, textRow2, textRow3],
|
||||||
|
]);
|
||||||
|
|
||||||
|
final editor = tester.editor..addNode(tableNode.node);
|
||||||
|
|
||||||
|
await editor.startTesting();
|
||||||
|
|
||||||
|
final selection = Selection.single(
|
||||||
|
path: getCellNode(tableNode.node, 0, 1)!.childAtIndexOrNull(0)!.path,
|
||||||
|
startOffset: 0,
|
||||||
|
endOffset: 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
await editor.updateSelection(selection);
|
||||||
|
|
||||||
|
// Test press ALT + Backspace, while skip in-table backspace command.
|
||||||
|
await editor.pressKey(
|
||||||
|
key: LogicalKeyboardKey.backspace,
|
||||||
|
isAltPressed: true,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getCellNode(tableNode.node, 0, 0)!
|
||||||
|
.childAtIndexOrNull(0)!
|
||||||
|
.delta
|
||||||
|
?.toPlainText(),
|
||||||
|
textRow1,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getCellNode(tableNode.node, 0, 1)!
|
||||||
|
.childAtIndexOrNull(0)!
|
||||||
|
.delta
|
||||||
|
?.toPlainText(),
|
||||||
|
textRow2,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getCellNode(tableNode.node, 0, 2)!
|
||||||
|
.childAtIndexOrNull(0)!
|
||||||
|
.delta
|
||||||
|
?.toPlainText(),
|
||||||
|
textRow3,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ensure the cursor is at the start of the new second row
|
||||||
|
expect(
|
||||||
|
editor.selection,
|
||||||
|
Selection.collapsed(Position(path: [0, 1, 0], offset: 0)),
|
||||||
|
);
|
||||||
|
|
||||||
|
await editor.dispose();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Before
|
||||||
|
// 🔽 delete from here
|
||||||
|
// |Cell in col 1|Cell in col 2|Cell in col 3|
|
||||||
|
// After
|
||||||
|
// |Cell in col 1|Cell in col 2|Cell in col 3|
|
||||||
|
testWidgets('Delete across multiple table columns', (tester) async {
|
||||||
|
const textCol1 = 'Cell in col 1';
|
||||||
|
const textCol2 = 'Cell in col 2';
|
||||||
|
const textCol3 = 'Cell in col 3';
|
||||||
|
|
||||||
|
final tableNode = TableNode.fromList([
|
||||||
|
[textCol1],
|
||||||
|
[textCol2],
|
||||||
|
[textCol3],
|
||||||
|
]);
|
||||||
|
|
||||||
|
final editor = tester.editor..addNode(tableNode.node);
|
||||||
|
|
||||||
|
await editor.startTesting();
|
||||||
|
|
||||||
|
final selection = Selection.single(
|
||||||
|
path: getCellNode(tableNode.node, 1, 0)!.childAtIndexOrNull(0)!.path,
|
||||||
|
startOffset: 0,
|
||||||
|
endOffset: 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
await editor.updateSelection(selection);
|
||||||
|
|
||||||
|
// Test press ALT + Backspace, while skip in-table backspace command.
|
||||||
|
await editor.pressKey(
|
||||||
|
key: LogicalKeyboardKey.backspace,
|
||||||
|
isAltPressed: true,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getCellNode(tableNode.node, 0, 0)!
|
||||||
|
.childAtIndexOrNull(0)!
|
||||||
|
.delta
|
||||||
|
?.toPlainText(),
|
||||||
|
textCol1,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getCellNode(tableNode.node, 1, 0)!
|
||||||
|
.childAtIndexOrNull(0)!
|
||||||
|
.delta
|
||||||
|
?.toPlainText(),
|
||||||
|
textCol2,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getCellNode(tableNode.node, 2, 0)!
|
||||||
|
.childAtIndexOrNull(0)!
|
||||||
|
.delta
|
||||||
|
?.toPlainText(),
|
||||||
|
textCol3,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
editor.selection,
|
||||||
|
Selection.collapsed(Position(path: [0, 1, 0], offset: 0)),
|
||||||
|
);
|
||||||
|
|
||||||
|
await editor.dispose();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue