Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: turn -> into to → in document (#7256)

Lucas0b0e10baa8f1
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/format_arrow_character.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/format_arrow_character.dart
index 6e6e111df1..379c7c61ba 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/format_arrow_character.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/format_arrow_character.dart
@@ -2,8 +2,10 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
const _greater = '>';
+const _dash = '-';
const _equals = '=';
-const _arrow = '⇒';
+const _equalGreater = '⇒';
+const _dashGreater = '→';
/// format '=' + '>' into an ⇒
///
@@ -18,11 +20,29 @@ final CharacterShortcutEvent customFormatGreaterEqual = CharacterShortcutEvent(
handler: (editorState) async => _handleDoubleCharacterReplacement(
editorState: editorState,
character: _greater,
- replacement: _arrow,
+ replacement: _equalGreater,
prefixCharacter: _equals,
),
);
+/// format '-' + '>' into ⇒
+///
+/// - support
+/// - desktop
+/// - mobile
+/// - web
+///
+final CharacterShortcutEvent customFormatDashGreater = CharacterShortcutEvent(
+ key: 'format - + > into ->',
+ character: _greater,
+ handler: (editorState) async => _handleDoubleCharacterReplacement(
+ editorState: editorState,
+ character: _greater,
+ replacement: _dashGreater,
+ prefixCharacter: _dash,
+ ),
+);
+
/// If [prefixCharacter] is null or empty, [character] is used
Future<bool> _handleDoubleCharacterReplacement({
required EditorState editorState,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart
index 080027d179..158d14f48e 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart
@@ -43,6 +43,7 @@ List<CharacterShortcutEvent> buildCharacterShortcutEvents(
),
customFormatGreaterEqual,
+ customFormatDashGreater,
customFormatNumberToNumberedList,
customFormatSignToHeading,
diff --git a/frontend/appflowy_flutter/test/unit_test/document/shortcuts/format_shortcut_test.dart b/frontend/appflowy_flutter/test/unit_test/document/shortcuts/format_shortcut_test.dart
new file mode 100644
index 0000000000..c5cb1c524d
--- /dev/null
+++ b/frontend/appflowy_flutter/test/unit_test/document/shortcuts/format_shortcut_test.dart
@@ -0,0 +1,62 @@
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/format_arrow_character.dart';
+import 'package:appflowy_backend/log.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ group('format shortcut:', () {
+ setUpAll(() {
+ Log.shared.disableLog = true;
+ });
+
+ tearDownAll(() {
+ Log.shared.disableLog = false;
+ });
+
+ test('turn = + > into ⇒', () async {
+ final document = Document.blank()
+ ..insert([
+ 0,
+ ], [
+ paragraphNode(text: '='),
+ ]);
+
+ final editorState = EditorState(document: document);
+ editorState.selection = Selection.collapsed(
+ Position(path: [0], offset: 1),
+ );
+
+ final result = await customFormatGreaterEqual.execute(editorState);
+ expect(result, true);
+
+ expect(editorState.document.root.children.length, 1);
+ final node = editorState.document.root.children[0];
+ expect(node.delta!.toPlainText(), '⇒');
+
+ editorState.dispose();
+ });
+
+ test('turn - + > into →', () async {
+ final document = Document.blank()
+ ..insert([
+ 0,
+ ], [
+ paragraphNode(text: '-'),
+ ]);
+
+ final editorState = EditorState(document: document);
+ editorState.selection = Selection.collapsed(
+ Position(path: [0], offset: 1),
+ );
+
+ final result = await customFormatDashGreater.execute(editorState);
+ expect(result, true);
+
+ expect(editorState.document.root.children.length, 1);
+ final node = editorState.document.root.children[0];
+ expect(node.delta!.toPlainText(), '→');
+
+ editorState.dispose();
+ });
+ });
+}