mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-08-04 14:57:27 +00:00

* feat: add ability to use : keyword to create emojis(#2797) * fix: emoji position error * chore: add integration test * chore: dismiss emoji picker while starting searching with space
45 lines
1.0 KiB
Dart
45 lines
1.0 KiB
Dart
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:universal_platform/universal_platform.dart';
|
|
|
|
import 'emoji_menu.dart';
|
|
|
|
const emojiCharacter = ':';
|
|
|
|
CharacterShortcutEvent emojiCommand(BuildContext context) =>
|
|
CharacterShortcutEvent(
|
|
key: 'Opens Emoji Menu',
|
|
character: emojiCharacter,
|
|
handler: (editorState) {
|
|
emojiMenuService ??= EmojiMenu(
|
|
context: context,
|
|
editorState: editorState,
|
|
);
|
|
return emojiCommandHandler(editorState, context);
|
|
},
|
|
);
|
|
|
|
EmojiMenuService? emojiMenuService;
|
|
|
|
Future<bool> emojiCommandHandler(
|
|
EditorState editorState,
|
|
BuildContext context,
|
|
) async {
|
|
final selection = editorState.selection;
|
|
|
|
if (UniversalPlatform.isMobile || selection == null) {
|
|
return false;
|
|
}
|
|
|
|
if (!selection.isCollapsed) {
|
|
await editorState.deleteSelection(selection);
|
|
}
|
|
|
|
await editorState.insertTextAtPosition(
|
|
emojiCharacter,
|
|
position: selection.start,
|
|
);
|
|
emojiMenuService?.show();
|
|
return true;
|
|
}
|