From ef0355d814e49791514405eba7c5a40b6d43caa6 Mon Sep 17 00:00:00 2001 From: Arshak Aghakaryan Date: Sun, 13 Mar 2022 16:39:24 +0400 Subject: [PATCH] Request keyboard focus when no child is found (#713) --- lib/src/widgets/editor.dart | 69 +++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 5cbb6e4c..2ae4cf00 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -591,44 +591,47 @@ class _QuillEditorSelectionGestureDetectorBuilder editor!.hideToolbar(); - if (delegate.selectionEnabled && !_isPositionSelected(details)) { - final _platform = Theme.of(_state.context).platform; - if (isAppleOS(_platform)) { - switch (details.kind) { - case PointerDeviceKind.mouse: - case PointerDeviceKind.stylus: - case PointerDeviceKind.invertedStylus: - // Precise devices should place the cursor at a precise position. - // If `Shift` key is pressed then - // extend current selection instead. - if (isShiftClick(details.kind)) { + try { + if (delegate.selectionEnabled && !_isPositionSelected(details)) { + final _platform = Theme.of(_state.context).platform; + if (isAppleOS(_platform)) { + switch (details.kind) { + case PointerDeviceKind.mouse: + case PointerDeviceKind.stylus: + case PointerDeviceKind.invertedStylus: + // Precise devices should place the cursor at a precise position. + // If `Shift` key is pressed then + // extend current selection instead. + if (isShiftClick(details.kind)) { + renderEditor! + ..extendSelection(details.globalPosition, + cause: SelectionChangedCause.tap) + ..onSelectionCompleted(); + } else { + renderEditor! + ..selectPosition(cause: SelectionChangedCause.tap) + ..onSelectionCompleted(); + } + + break; + case PointerDeviceKind.touch: + case PointerDeviceKind.unknown: + // On macOS/iOS/iPadOS a touch tap places the cursor at the edge + // of the word. renderEditor! - ..extendSelection(details.globalPosition, - cause: SelectionChangedCause.tap) + ..selectWordEdge(SelectionChangedCause.tap) ..onSelectionCompleted(); - } else { - renderEditor! - ..selectPosition(cause: SelectionChangedCause.tap) - ..onSelectionCompleted(); - } - - break; - case PointerDeviceKind.touch: - case PointerDeviceKind.unknown: - // On macOS/iOS/iPadOS a touch tap places the cursor at the edge - // of the word. - renderEditor! - ..selectWordEdge(SelectionChangedCause.tap) - ..onSelectionCompleted(); - break; + break; + } + } else { + renderEditor! + ..selectPosition(cause: SelectionChangedCause.tap) + ..onSelectionCompleted(); } - } else { - renderEditor! - ..selectPosition(cause: SelectionChangedCause.tap) - ..onSelectionCompleted(); } + } finally { + _state._requestKeyboard(); } - _state._requestKeyboard(); } @override