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

* chore: bump version 0.8.2

* feat: turn -> into to → in document

* Revert "chore: bump version 0.8.2"

This reverts commit 45efd4d7d7bd8436ee831c5af66dbed0a2bd7f77.

* test: add shortcut tests
This commit is contained in:
Lucas 2025-01-22 15:05:22 +08:00 committed by GitHub
parent ec18a3c443
commit 0b0e10baa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 85 additions and 2 deletions

View File

@ -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,

View File

@ -43,6 +43,7 @@ List<CharacterShortcutEvent> buildCharacterShortcutEvents(
),
customFormatGreaterEqual,
customFormatDashGreater,
customFormatNumberToNumberedList,
customFormatSignToHeading,

View File

@ -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();
});
});
}