-
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: support skipping slice attributes (#901)
* feat: skip slicing the next inserted text if the previous text has been formatted * test: skip slicing attribute test * feat: reset slice flag when updating selection
- Loading branch information
Showing
4 changed files
with
82 additions
and
2 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
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,66 @@ | ||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../new/infra/testable_editor.dart'; | ||
|
||
void main() async { | ||
setUpAll(() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
}); | ||
|
||
// input `Hello` World | ||
// only the `Hello` has the code style | ||
testWidgets('skip attributes if pressing space', (tester) async { | ||
final editor = tester.editor..addEmptyParagraph(); | ||
await editor.startTesting(); | ||
await tester.pumpAndSettle(); | ||
|
||
final selection = Selection.collapsed(Position(path: [0])); | ||
await editor.updateSelection(selection); | ||
const text = '`Hello` World'; | ||
for (var i = 0; i < text.length; i++) { | ||
await editor.ime.typeText(text[i]); | ||
} | ||
|
||
final node = editor.editorState.getNodeAtPath([0]); | ||
final delta = node?.delta; | ||
expect(delta?.toPlainText(), 'Hello World'); | ||
expect(delta?.toJson(), [ | ||
{ | ||
'insert': 'Hello', | ||
'attributes': {'code': true}, | ||
}, | ||
{'insert': ' World'}, | ||
]); | ||
}); | ||
|
||
testWidgets('keep attributes if pressing backspace', (tester) async { | ||
final editor = tester.editor..addEmptyParagraph(); | ||
await editor.startTesting(); | ||
await tester.pumpAndSettle(); | ||
|
||
final selection = Selection.collapsed(Position(path: [0])); | ||
await editor.updateSelection(selection); | ||
const text1 = '`Hello` '; | ||
for (var i = 0; i < text1.length; i++) { | ||
await editor.ime.typeText(text1[i]); | ||
} | ||
|
||
await tester.editor.pressKey(key: LogicalKeyboardKey.backspace); | ||
|
||
const text2 = 'World'; | ||
for (var i = 0; i < text2.length; i++) { | ||
await editor.ime.typeText(text2[i]); | ||
} | ||
|
||
final node = editor.editorState.getNodeAtPath([0]); | ||
final delta = node?.delta; | ||
expect(delta?.toJson(), [ | ||
{ | ||
'insert': 'HelloWorld', | ||
'attributes': {'code': true}, | ||
}, | ||
]); | ||
}); | ||
} |