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: overwriting a selected text removes more than expected (#7714)
Mornf4af47728fb5
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_selection_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_selection_test.dartindex bd0fd18c50..de1cb880a5 100644--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_selection_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_selection_test.dart@@ -1,5 +1,6 @@import 'package:appflowy_editor/appflowy_editor.dart';import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';import 'package:integration_test/integration_test.dart';@@ -47,5 +48,41 @@ void main() {expect(editorState.selection!.start.offset, 0);});++ testWidgets('select and delete text', (tester) async {+ await tester.initializeAppFlowy();+ await tester.tapAnonymousSignInButton();++ /// create a new document+ await tester.createNewPageWithNameUnderParent();++ /// input text+ final editor = tester.editor;+ final editorState = editor.getCurrentEditorState();++ const inputText = 'Test for text selection and deletion';+ final texts = inputText.split(' ');+ await editor.tapLineOfEditorAt(0);+ await tester.ime.insertText(inputText);++ /// selecte and delete+ int index = 0;+ while (texts.isNotEmpty) {+ final text = texts.removeAt(0);+ await tester.editor.updateSelection(+ Selection(+ start: Position(path: [0], offset: index),+ end: Position(path: [0], offset: index + text.length),+ ),+ );+ await tester.simulateKeyEvent(LogicalKeyboardKey.delete);+ index++;+ }++ /// excpete the text value is correct+ final node = editorState.getNodeAtPath([0])!;+ final nodeText = node.delta?.toPlainText() ?? '';+ expect(nodeText, ' ' * (index - 1));+ });});}diff --git a/frontend/appflowy_flutter/lib/plugins/emoji/emoji_actions_command.dart b/frontend/appflowy_flutter/lib/plugins/emoji/emoji_actions_command.dartindex ffe25be8bd..9d386b36be 100644--- a/frontend/appflowy_flutter/lib/plugins/emoji/emoji_actions_command.dart+++ b/frontend/appflowy_flutter/lib/plugins/emoji/emoji_actions_command.dart@@ -38,10 +38,6 @@ Future<bool> emojiCommandHandler(return false;}- if (!selection.isCollapsed) {- await editorState.deleteSelection(selection);- }-final node = editorState.getNodeAtPath(selection.end.path);final delta = node?.delta;if (node == null ||@@ -58,6 +54,8 @@ Future<bool> emojiCommandHandler(if (previousCharacter != _emojiCharacter) return false;if (!context.mounted) return false;+ if (!selection.isCollapsed) return false;+await editorState.insertTextAtPosition(character,position: selection.start,