mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -04:00
fix: overwriting a selected text removes more than expected
This commit is contained in:
parent
b3a4a9ba04
commit
032124c002
2 changed files with 39 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
|
|
||||||
|
@ -47,5 +48,41 @@ void main() {
|
||||||
|
|
||||||
expect(editorState.selection!.start.offset, 0);
|
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));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,6 @@ Future<bool> emojiCommandHandler(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!selection.isCollapsed) {
|
|
||||||
await editorState.deleteSelection(selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
final node = editorState.getNodeAtPath(selection.end.path);
|
final node = editorState.getNodeAtPath(selection.end.path);
|
||||||
final delta = node?.delta;
|
final delta = node?.delta;
|
||||||
if (node == null ||
|
if (node == null ||
|
||||||
|
@ -58,6 +54,8 @@ Future<bool> emojiCommandHandler(
|
||||||
if (previousCharacter != _emojiCharacter) return false;
|
if (previousCharacter != _emojiCharacter) return false;
|
||||||
if (!context.mounted) return false;
|
if (!context.mounted) return false;
|
||||||
|
|
||||||
|
if (!selection.isCollapsed) return false;
|
||||||
|
|
||||||
await editorState.insertTextAtPosition(
|
await editorState.insertTextAtPosition(
|
||||||
character,
|
character,
|
||||||
position: selection.start,
|
position: selection.start,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue