mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-12-27 15:13:46 +00:00
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:
parent
ec18a3c443
commit
0b0e10baa8
@ -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,
|
||||
|
||||
@ -43,6 +43,7 @@ List<CharacterShortcutEvent> buildCharacterShortcutEvents(
|
||||
),
|
||||
|
||||
customFormatGreaterEqual,
|
||||
customFormatDashGreater,
|
||||
|
||||
customFormatNumberToNumberedList,
|
||||
customFormatSignToHeading,
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user