-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: undo style of markdown and retain characters * test: add tests * test: macos meta instead of control
- Loading branch information
Showing
4 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
test/new/editor_component/service/shortcuts/character_shortcuts/undo_markdown_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:flutter/services.dart'; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
|
||
import '../../../../infra/testable_editor.dart'; | ||
|
||
void main() async { | ||
group('undo_markdown_test.dart', () { | ||
testWidgets('single character markdown shortcut then undo', (tester) async { | ||
const helloWorld = "_Hello world_"; | ||
|
||
final editor = tester.editor..addEmptyParagraph(); | ||
await editor.startTesting(); | ||
|
||
await editor.updateSelection(Selection.collapsed(Position(path: [0]))); | ||
await editor.ime.typeText('_Hello world'); | ||
await editor.ime.typeText('_'); | ||
|
||
Delta delta = editor.nodeAtPath([0])!.delta!; | ||
expect(delta.length, 'Hello world'.length); | ||
expect(delta.first.attributes![AppFlowyRichTextKeys.italic], true); | ||
|
||
final key = PlatformExtension.isMacOS | ||
? LogicalKeyboardKey.meta | ||
: LogicalKeyboardKey.control; | ||
await tester.sendKeyDownEvent(key); | ||
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyZ); | ||
await tester.sendKeyUpEvent(key); | ||
await tester.sendKeyUpEvent(LogicalKeyboardKey.keyZ); | ||
|
||
delta = editor.nodeAtPath([0])!.delta!; | ||
expect(delta.length, helloWorld.length); | ||
expect(delta.toPlainText(), helloWorld); | ||
expect(delta.first.attributes?[AppFlowyRichTextKeys.italic], null); | ||
|
||
await editor.dispose(); | ||
}); | ||
|
||
testWidgets('multi character markdown shortcut then undo', (tester) async { | ||
const helloWorld = "__Hello world__"; | ||
|
||
final editor = tester.editor..addEmptyParagraph(); | ||
await editor.startTesting(); | ||
|
||
await editor.updateSelection(Selection.collapsed(Position(path: [0]))); | ||
await editor.ime.typeText('__Hello world_'); | ||
await editor.ime.typeText('_'); | ||
|
||
Delta delta = editor.nodeAtPath([0])!.delta!; | ||
expect(delta.length, 'Hello world'.length); | ||
expect(delta.first.attributes![AppFlowyRichTextKeys.bold], true); | ||
|
||
final key = PlatformExtension.isMacOS | ||
? LogicalKeyboardKey.meta | ||
: LogicalKeyboardKey.control; | ||
await tester.sendKeyDownEvent(key); | ||
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyZ); | ||
await tester.sendKeyUpEvent(key); | ||
await tester.sendKeyUpEvent(LogicalKeyboardKey.keyZ); | ||
|
||
delta = editor.nodeAtPath([0])!.delta!; | ||
expect(delta.length, helloWorld.length); | ||
expect(delta.toPlainText(), helloWorld); | ||
expect(delta.first.attributes?[AppFlowyRichTextKeys.italic], null); | ||
|
||
await editor.dispose(); | ||
}); | ||
}); | ||
} |