Skip to content

Commit

Permalink
feat: support formatting greater hyphen to single arrow (#665)
Browse files Browse the repository at this point in the history
* feat: support formatting greater hyphen to single arrow

* refactor: renamed test group description

* refactor: formatted code file using dart formatter

* refactor: removes GreaterHyphen shortcut event from standard shortcuts

* fix: enable formatGreaterHyphen shortcut in test mode

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
  • Loading branch information
Jayaprakash-dev and LucasXu0 authored Jan 14, 2024
1 parent 3feff00 commit dccd4e8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
delta is TextEditingDeltaNonTextUpdate) {
composingTextRange = delta.composing;
}

// solve the issue where the Chinese IME doesn't continue deleting after the input content has been deleted.
if (composingTextRange?.isCollapsed ?? false) {
composingTextRange = TextRange.empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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_arrow_character.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();
});
});
}
4 changes: 4 additions & 0 deletions test/new/infra/testable_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class TestableEditor {
...TestableFindAndReplaceCommands(context: context)
.testableFindAndReplaceCommands,
],
characterShortcutEvents: [
...standardCharacterShortcutEvents,
formatGreaterHyphen,
],
editorStyle: inMobile
? EditorStyle.mobile(
defaultTextDirection: defaultTextDirection,
Expand Down

0 comments on commit dccd4e8

Please sign in to comment.