Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support formatting greater hyphen to single arrow #665

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading