fix: enter after emoji will create a softbreak on mobile (#1010)

* fix: enter after emoji will create a softbreak

* test: enter after emoji will create a softbreak
This commit is contained in:
Lucas 2024-12-31 15:10:41 +08:00 • committed by GitHub
commit 9f6a29968e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -5,6 +5,11 @@ Future<bool> executeCharacterShortcutEvent(
String? character, String? character,
List<CharacterShortcutEvent> characterShortcutEvents, List<CharacterShortcutEvent> characterShortcutEvents,
) async { ) async {
// if the character is a space + enter, we should execute the enter event
if (character == ' \n') {
character = '\n';
}
if (character?.length != 1) { if (character?.length != 1) {
return false; return false;
} }

View file

@ -0,0 +1,31 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/ime/delta_input_impl.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('character shortcut on insert', () {
WidgetsFlutterBinding.ensureInitialized();
test('call', () async {
final editorState = EditorState.blank();
editorState.selection = Selection.collapsed(
Position(path: [0]),
);
await onInsert(
const TextEditingDeltaInsertion(
textInserted: ' \n',
composing: TextRange.empty,
oldText: '',
selection: TextSelection.collapsed(offset: 0),
insertionOffset: 0,
),
editorState,
[insertNewLine],
);
final nodes = editorState.document.root.children;
expect(nodes.length, 2);
});
});
}