Skip to content

Commit 4a2e1a3

Browse files
tjarvstrandCatHood0
and
CatHood0
authored
Focus and open context menu on right click if unfocused (singerdmx#2477)
Co-authored-by: CatHood0 <[email protected]>
1 parent 93f283c commit 4a2e1a3

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414

15-
* Removed unicode from `QuillText` element that causes weird caret behavior on empty lines [#2453](https://github.com/singerdmx/flutter-quill/pull/2453).
15+
* Remove unicode from `QuillText` element that causes weird caret behavior on empty lines [#2453](https://github.com/singerdmx/flutter-quill/pull/2453).
16+
* Focus and open context menu on right click if unfocused [#2477](https://github.com/singerdmx/flutter-quill/pull/2477).
1617
* Update QuillController `length` extension method deprecation message [#2483](https://github.com/singerdmx/flutter-quill/pull/2483).
1718

1819
## [11.0.0] - 2025-02-16

lib/src/editor/editor.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/gestures.dart';
77
import 'package:flutter/material.dart';
88
import 'package:flutter/rendering.dart';
9+
import 'package:flutter/scheduler.dart';
910
import 'package:flutter/services.dart';
1011

1112
import '../common/utils/platform.dart';
@@ -557,6 +558,28 @@ class _QuillEditorSelectionGestureDetectorBuilder
557558
}
558559
}
559560

561+
/// onSingleTapUp for mouse right click
562+
@override
563+
void onSecondarySingleTapUp(TapUpDetails details) {
564+
if (delegate.selectionEnabled &&
565+
renderEditor != null &&
566+
renderEditor!.selection.isCollapsed) {
567+
renderEditor!.selectPositionAt(
568+
from: details.globalPosition,
569+
cause: SelectionChangedCause.longPress,
570+
);
571+
}
572+
573+
if (renderEditor?._hasFocus == false) {
574+
_state._requestKeyboard();
575+
SchedulerBinding.instance.addPostFrameCallback((_) {
576+
super.onSecondarySingleTapUp(details);
577+
});
578+
} else {
579+
super.onSecondarySingleTapUp(details);
580+
}
581+
}
582+
560583
@override
561584
void onSingleLongTapStart(LongPressStartDetails details) {
562585
if (_state.configurations.onSingleLongTapStart != null) {

lib/src/editor/widgets/delegate.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ class EditorTextSelectionGestureDetectorBuilder {
199199
/// onSingleTapUp for mouse right click
200200
@protected
201201
void onSecondarySingleTapUp(TapUpDetails details) {
202-
// added to show toolbar by right click
203-
if (checkSelectionToolbarShouldShow(isAdditionalAction: true)) {
204-
editor!.showToolbar();
205-
}
202+
SchedulerBinding.instance.addPostFrameCallback((_) {
203+
// added to show toolbar by right click
204+
if (checkSelectionToolbarShouldShow(isAdditionalAction: true)) {
205+
editor!.showToolbar();
206+
}
207+
});
206208
}
207209

208210
/// Handler for [EditorTextSelectionGestureDetector.onSingleTapCancel].

test/bug_fix_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ void main() {
162162
await tester.tap(find.byType(QuillEditor),
163163
buttons: kSecondaryButton, kind: device);
164164
await tester.pumpAndSettle();
165+
while (find.byType(AdaptiveTextSelectionToolbar).evaluate().isEmpty) {
166+
await tester.pumpAndSettle();
167+
}
165168

166169
// Verify custom widget shows
167170
expect(find.byType(AdaptiveTextSelectionToolbar), findsAny);

0 commit comments

Comments
 (0)