From 9877d55a50db45f7c629f2172dd848ef07e9fabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 27 Aug 2021 19:18:36 +0200 Subject: macOS: Report preedit cursor position and cursor visibility correctly Unfortunately QInputMethodEvent::Cursor defines length == 0 as the cursor being hidden, and length > 0 as being visible. This is the opposite of what native macOS application do. A future improvement here would be to base the QInputMethodEvent logic on QStyle::SH_BlinkCursorWhenTextSelected, which we already respect for normal selections. That would also allow us to use QInputMethodEvent::Cursor to set the preedit selection, which we currently have to fake via QInputMethodEvent::TextFormat. Pick-to: 6.2 Change-Id: I75b5d8c5403283a0988355e440a98b4df35ec995 Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/cocoa/qnsview_complextext.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index 05c0418ee7..39739d9725 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -185,9 +185,16 @@ QString preeditString = QString::fromNSString(isAttributedString ? [text string] : text); QList preeditAttributes; - preeditAttributes << QInputMethodEvent::Attribute( - QInputMethodEvent::Cursor, selectedRange.location + selectedRange.length, true); + // The QInputMethodEvent::Cursor specifies that the length + // determines whether the cursor is visible or not, but uses + // logic opposite of that of native AppKit application, where + // the cursor is visible if there's no selection, and hidden + // if there's a selection. Instead of passing on the length + // directly we need to inverse the logic. + const bool showCursor = !selectedRange.length; + preeditAttributes << QInputMethodEvent::Attribute( + QInputMethodEvent::Cursor, selectedRange.location, showCursor); // QInputMethodEvent::Selection unfortunately doesn't apply to the // preedit text, and QInputMethodEvent::Cursor which does, doesn't -- cgit v1.2.3