Skip to content

Commit

Permalink
Fix persistent contextual menu when selecting all on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
amantoux committed Dec 8, 2023
1 parent 416244c commit 2fb7582
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,35 @@ class RawEditorState extends EditorState
),
cause,
);
userUpdateTextEditingValue(
textEditingValue.copyWith(
selection: TextSelection(
baseOffset: 0, extentOffset: textEditingValue.text.length),
),
cause,
);

if (cause == SelectionChangedCause.toolbar) {
bringIntoView(textEditingValue.selection.extent);
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.iOS:
case TargetPlatform.fuchsia:
break;
case TargetPlatform.macOS:
case TargetPlatform.linux:
case TargetPlatform.windows:
hideToolbar();
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
bringIntoView(textEditingValue.selection.extent);
case TargetPlatform.macOS:
case TargetPlatform.iOS:

Check warning on line 939 in packages/fleather/lib/src/widgets/editor.dart

View check run for this annotation

Codecov / codecov/patch

packages/fleather/lib/src/widgets/editor.dart#L939

Added line #L939 was not covered by tests
break;
}
}
}

Expand Down
46 changes: 46 additions & 0 deletions packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,52 @@ void main() {
const TypeMatcher<DesktopTextSelectionControls>());
}, [TargetPlatform.linux]);

testWidgetsWithPlatform('selectAll for macOS', (tester) async {
final document = ParchmentDocument.fromJson([
{'insert': 'Test\nAnother line\n'}
]);
final editor = EditorSandBox(tester: tester, document: document);
await editor.pump();
await tester.tapAt(
tester.getTopLeft(find.byType(FleatherEditor)) + const Offset(1, 1),
buttons: kSecondaryMouseButton);
await tester.pump();
expect(
find.byType(CupertinoDesktopTextSelectionToolbar), findsOneWidget);
await tester.tap(find.text('Select All')); // Select All in macOS
await tester.pump();
expect(
editor.selection,
const TextSelection(
baseOffset: 0,
extentOffset: 17,
affinity: TextAffinity.upstream));
expect(find.byType(CupertinoDesktopTextSelectionToolbar), findsNothing);
}, [TargetPlatform.macOS]);

testWidgetsWithPlatform('selectAll for Windows/Linux', (tester) async {
final document = ParchmentDocument.fromJson([
{'insert': 'Test\nAnother line\n'}
]);
final editor = EditorSandBox(tester: tester, document: document);
await editor.pump();
await tester.tapAt(
tester.getTopLeft(find.byType(FleatherEditor)) + const Offset(1, 1),
buttons: kSecondaryMouseButton);
await tester.pump();
expect(find.byType(DesktopTextSelectionToolbar), findsOneWidget);
await tester
.tap(find.text('Select all')); // Select all in other than macOS
await tester.pump();
expect(
editor.selection,
const TextSelection(
baseOffset: 0,
extentOffset: 17,
affinity: TextAffinity.upstream));
expect(find.byType(DesktopTextSelectionToolbar), findsNothing);
}, [TargetPlatform.linux, TargetPlatform.windows]);

testWidgetsWithPlatform(
'Triple tap selects paragraph on platforms other than Linux',
(tester) async {
Expand Down

0 comments on commit 2fb7582

Please sign in to comment.