Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always keep natural order of selection boundaries #401

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1264,9 +1264,9 @@ class RawEditorState extends EditorState
final TextSelection selection = textEditingValue.selection;
widget.clipboardManager.setData(FleatherClipboardData(
plainText: selection.textInside(textEditingValue.text),
delta: controller.document
.toDelta()
.slice(selection.baseOffset, selection.extentOffset),
delta: controller.document.toDelta().slice(
math.min(selection.baseOffset, selection.extentOffset),
math.max(selection.baseOffset, selection.extentOffset)),
));
}

Expand Down
29 changes: 29 additions & 0 deletions packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,35 @@ void main() {
expect(sentData?.delta, Delta()..insert('t T'));
});

testWidgets(
'Copy sends correct data to clipboard manager when selection extents are inverted',
(tester) async {
prepareClipboard();
FleatherClipboardData? sentData;
final editor = EditorSandBox(
tester: tester,
document: ParchmentDocument.fromJson([
{'insert': 'Test Text\n'}
]),
autofocus: true,
clipboardManager: FleatherCustomClipboardManager(
getData: () => throw UnimplementedError(),
setData: (data) async => sentData = data,
),
);
await editor.pump();
final RawEditorState state =
tester.state<RawEditorState>(find.byType(RawEditor));
await editor.updateSelection(base: 6, extent: 3);
state.showToolbar(createIfNull: true);
await tester.pump();
final finder = find.text('Copy');
await tester.tap(finder);
await tester.pumpAndSettle(throttleDuration);
expect(sentData?.plainText, 't T');
expect(sentData?.delta, Delta()..insert('t T'));
});

testWidgets('Cut intent sends data to clipboard manager', (tester) async {
prepareClipboard();
FleatherClipboardData? sentData;
Expand Down
Loading