Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: emoji position
Vincent Chanc554720dffe2
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dartindex 03ae4ccc56..b1e6525c49 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart@@ -475,10 +475,35 @@ class Delta extends Iterable<TextOperation> {return _operations.map((e) => e.toJson()).toList();}- String toRawString() {+ int prevRunePosition(int pos) {+ if (pos == 0) {+ return pos;+ }_rawString ??=_operations.whereType<TextInsert>().map((op) => op.content).join();_runeIndexes ??= stringIndexes(_rawString!);+ return _runeIndexes![pos - 1];+ }++ int nextRunePosition(int pos) {+ final stringContent = toRawString();+ if (pos >= stringContent.length - 1) {+ return stringContent.length;+ }+ _runeIndexes ??= stringIndexes(_rawString!);++ for (var i = pos + 1; i < _runeIndexes!.length; i++) {+ if (_runeIndexes![i] != pos) {+ return _runeIndexes![i];+ }+ }++ return pos;+ }++ String toRawString() {+ _rawString ??=+ _operations.whereType<TextInsert>().map((op) => op.content).join();return _rawString!;}diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dartindex 83243d2dc7..826308e565 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart@@ -12,8 +12,8 @@ int _endOffsetOfNode(Node node) {extension on Position {Position? goLeft(EditorState editorState) {+ final node = editorState.document.nodeAtPath(path)!;if (offset == 0) {- final node = editorState.document.nodeAtPath(path)!;final prevNode = node.previous;if (prevNode != null) {return Position(@@ -22,7 +22,11 @@ extension on Position {return null;}- return Position(path: path, offset: offset - 1);+ if (node is TextNode) {+ return Position(path: path, offset: node.delta.prevRunePosition(offset));+ } else {+ return Position(path: path, offset: offset);+ }}Position? goRight(EditorState editorState) {@@ -36,7 +40,11 @@ extension on Position {return null;}- return Position(path: path, offset: offset + 1);+ if (node is TextNode) {+ return Position(path: path, offset: node.delta.nextRunePosition(offset));+ } else {+ return Position(path: path, offset: offset);+ }}}