-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: paste plaintext shortcut (#338)
* feat: shortcut for pasting plaintext * test: paste without formatting * chore: use text directly * refactor: add cut command
- Loading branch information
1 parent
c3f62b3
commit 2b517b2
Showing
3 changed files
with
182 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
129 changes: 129 additions & 0 deletions
129
test/new/service/shortcuts/command_shortcut_events/paste_command_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,129 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../../../infra/testable_editor.dart'; | ||
|
||
const text = 'Welcome to AppFlowy Editor 🔥!'; | ||
|
||
void main() async { | ||
setUp(() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
}); | ||
|
||
group('paste_command_test.dart paste_plaintext', () { | ||
testWidgets('works with formatted text', (tester) async { | ||
final editor = tester.editor..addParagraph(initialText: text); | ||
await editor.startTesting(); | ||
|
||
await _applyFormatting( | ||
editor, | ||
BuiltInAttributeKey.underline, | ||
LogicalKeyboardKey.keyU, | ||
); | ||
|
||
await _applyFormatting( | ||
editor, | ||
BuiltInAttributeKey.italic, | ||
LogicalKeyboardKey.keyI, | ||
); | ||
|
||
await _applyFormatting( | ||
editor, | ||
BuiltInAttributeKey.bold, | ||
LogicalKeyboardKey.keyB, | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
final selection = Selection.single( | ||
path: [0], | ||
startOffset: 0, | ||
endOffset: 7, | ||
); | ||
|
||
await editor.updateSelection(selection); | ||
await editor.pressKey( | ||
key: LogicalKeyboardKey.keyC, | ||
isMetaPressed: Platform.isMacOS, | ||
isControlPressed: Platform.isWindows || Platform.isLinux, | ||
); | ||
|
||
await editor.updateSelection(selection); | ||
|
||
await editor.pressKey( | ||
key: LogicalKeyboardKey.keyV, | ||
isShiftPressed: true, | ||
isMetaPressed: Platform.isMacOS, | ||
isControlPressed: Platform.isWindows || Platform.isLinux, | ||
); | ||
|
||
await editor.updateSelection(selection); | ||
final node = editor.nodeAtPath([0]); | ||
|
||
_checkSelectionNotFormatted( | ||
node!, | ||
selection, | ||
BuiltInAttributeKey.bold, | ||
); | ||
|
||
_checkSelectionNotFormatted( | ||
node, | ||
selection, | ||
BuiltInAttributeKey.underline, | ||
); | ||
|
||
_checkSelectionNotFormatted( | ||
node, | ||
selection, | ||
BuiltInAttributeKey.italic, | ||
); | ||
|
||
await editor.dispose(); | ||
}); | ||
}); | ||
} | ||
|
||
Future<void> _applyFormatting( | ||
TestableEditor editor, | ||
String matchStyle, | ||
LogicalKeyboardKey key, | ||
) async { | ||
final selection = Selection.single( | ||
path: [0], | ||
startOffset: 0, | ||
endOffset: 7, | ||
); | ||
await editor.updateSelection(selection); | ||
await editor.pressKey( | ||
key: key, | ||
isMetaPressed: Platform.isMacOS, | ||
isControlPressed: Platform.isWindows || Platform.isLinux, | ||
); | ||
final node = editor.nodeAtPath([0]); | ||
|
||
expect( | ||
node!.allSatisfyInSelection(selection, (delta) { | ||
return delta.whereType<TextInsert>().every( | ||
(el) => el.attributes?[matchStyle] == true, | ||
); | ||
}), | ||
true, | ||
); | ||
} | ||
|
||
void _checkSelectionNotFormatted( | ||
Node node, | ||
Selection selection, | ||
String matchStyle, | ||
) { | ||
expect( | ||
node.allSatisfyInSelection(selection, (delta) { | ||
return delta.whereType<TextInsert>().every( | ||
(el) => el.attributes?[matchStyle] != true, | ||
); | ||
}), | ||
true, | ||
); | ||
} |