From c5fd29672c4b41afb6c758aefec81379404e7064 Mon Sep 17 00:00:00 2001 From: Jayaprakash Date: Wed, 10 Jan 2024 22:44:26 +0530 Subject: [PATCH 1/5] feat: support formatting greater hyphen to single arrow --- .../standard_block_components.dart | 3 ++ .../double/format_arrow_character.dart | 21 ++++++++ .../format_greater_hyphen_test.dart | 52 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart diff --git a/lib/src/editor/block_component/standard_block_components.dart b/lib/src/editor/block_component/standard_block_components.dart index 495a38df4..c68e8e936 100644 --- a/lib/src/editor/block_component/standard_block_components.dart +++ b/lib/src/editor/block_component/standard_block_components.dart @@ -97,6 +97,9 @@ final List standardCharacterShortcutEvents = [ // convert => to arrow formatGreaterEqual, + + // convert -> to single arrow (→) + formatGreaterHyphen, ]; final List standardCommandShortcutEvents = [ diff --git a/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart b/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart index 99e64fb86..e2766cfc2 100644 --- a/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart +++ b/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart @@ -22,3 +22,24 @@ final CharacterShortcutEvent formatGreaterEqual = CharacterShortcutEvent( prefixCharacter: _equals, ), ); + +const _hyphen = '-'; +const _singleArrow = '→'; + +/// format '-' + '>' into an → +/// +/// - support +/// - desktop +/// - mobile +/// - web +/// +final CharacterShortcutEvent formatGreaterHyphen = CharacterShortcutEvent( + key: 'format - + > into →', + character: _greater, + handler: (editorState) async => handleDoubleCharacterReplacement( + editorState: editorState, + character: _greater, + replacement: _singleArrow, + prefixCharacter: _hyphen, + ), +); \ No newline at end of file diff --git a/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart b/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart new file mode 100644 index 000000000..c7dd099c4 --- /dev/null +++ b/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart @@ -0,0 +1,52 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../../../../infra/testable_editor.dart'; + +const _hyphen = '-'; +const _greater = '>'; +const _singleArrow = '→'; + +void main() async { + group('format_greater_hyphen.dart', () { + testWidgets('hyphen + greater to single arrow', (tester) async { + final editor = tester.editor..addEmptyParagraph(); + await editor.startTesting(); + + await editor.updateSelection(Selection.collapsed(Position(path: [0]))); + + await editor.ime.typeText(_hyphen); + await editor.ime.typeText(_greater); + + final delta = editor.nodeAtPath([0])!.delta!; + expect(delta.length, 1); + expect(delta.toPlainText(), _singleArrow); + + await editor.dispose(); + }); + + testWidgets('hyphen + greater to single arrow with selection', (tester) async { + const welcome = 'Welcome'; + const initialText = '$_hyphen$welcome'; + + final editor = tester.editor..addParagraph(initialText: initialText); + await editor.startTesting(); + + await editor.updateSelection( + Selection.single( + path: [0], + startOffset: 1, + endOffset: initialText.length, + ), + ); + + await editor.ime.typeText(_greater); + + final delta = editor.nodeAtPath([0])!.delta!; + expect(delta.length, 1); + expect(delta.toPlainText(), _singleArrow); + + await editor.dispose(); + }); + }); +} From 7a230f9e006f8c6ddb3526105152a4a6bf39b365 Mon Sep 17 00:00:00 2001 From: Jayaprakash Date: Wed, 10 Jan 2024 22:55:48 +0530 Subject: [PATCH 2/5] refactor: renamed test group description --- .../character_shortcuts/format_greater_hyphen_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart b/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart index c7dd099c4..3df6b1063 100644 --- a/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart +++ b/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart @@ -8,7 +8,7 @@ const _greater = '>'; const _singleArrow = '→'; void main() async { - group('format_greater_hyphen.dart', () { + group('format_arrow_character.dart', () { testWidgets('hyphen + greater to single arrow', (tester) async { final editor = tester.editor..addEmptyParagraph(); await editor.startTesting(); From 60d81135420cb6e927082cad25f73ce794f175db Mon Sep 17 00:00:00 2001 From: Jayaprakash Date: Wed, 10 Jan 2024 23:04:12 +0530 Subject: [PATCH 3/5] refactor: formatted code file using dart formatter --- .../shortcuts/character/double/format_arrow_character.dart | 2 +- .../character_shortcuts/format_greater_hyphen_test.dart | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart b/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart index e2766cfc2..888c56e1a 100644 --- a/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart +++ b/lib/src/editor/editor_component/service/shortcuts/character/double/format_arrow_character.dart @@ -42,4 +42,4 @@ final CharacterShortcutEvent formatGreaterHyphen = CharacterShortcutEvent( replacement: _singleArrow, prefixCharacter: _hyphen, ), -); \ No newline at end of file +); diff --git a/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart b/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart index 3df6b1063..876dca82f 100644 --- a/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart +++ b/test/new/editor_component/service/shortcuts/character_shortcuts/format_greater_hyphen_test.dart @@ -25,7 +25,8 @@ void main() async { await editor.dispose(); }); - testWidgets('hyphen + greater to single arrow with selection', (tester) async { + testWidgets('hyphen + greater to single arrow with selection', + (tester) async { const welcome = 'Welcome'; const initialText = '$_hyphen$welcome'; From cafbf89ac0a668b8a2527abf017958ee7b9421b8 Mon Sep 17 00:00:00 2001 From: Jayaprakash Date: Thu, 11 Jan 2024 12:39:34 +0530 Subject: [PATCH 4/5] refactor: removes GreaterHyphen shortcut event from standard shortcuts --- lib/src/editor/block_component/standard_block_components.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/src/editor/block_component/standard_block_components.dart b/lib/src/editor/block_component/standard_block_components.dart index c68e8e936..495a38df4 100644 --- a/lib/src/editor/block_component/standard_block_components.dart +++ b/lib/src/editor/block_component/standard_block_components.dart @@ -97,9 +97,6 @@ final List standardCharacterShortcutEvents = [ // convert => to arrow formatGreaterEqual, - - // convert -> to single arrow (→) - formatGreaterHyphen, ]; final List standardCommandShortcutEvents = [ From 8202f6469747089685dc3e4cfa9ee7626a2eb03a Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Sat, 13 Jan 2024 23:26:10 +0800 Subject: [PATCH 5/5] fix: enable formatGreaterHyphen shortcut in test mode --- test/new/infra/testable_editor.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/new/infra/testable_editor.dart b/test/new/infra/testable_editor.dart index ae66af3c9..d20211d4a 100644 --- a/test/new/infra/testable_editor.dart +++ b/test/new/infra/testable_editor.dart @@ -81,6 +81,10 @@ class TestableEditor { ...TestableFindAndReplaceCommands(context: context) .testableFindAndReplaceCommands, ], + characterShortcutEvents: [ + ...standardCharacterShortcutEvents, + formatGreaterHyphen, + ], editorStyle: inMobile ? EditorStyle.mobile( defaultTextDirection: defaultTextDirection,