diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-27 19:18:36 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-09-06 14:37:43 +0200 |
commit | 9877d55a50db45f7c629f2172dd848ef07e9fabe (patch) | |
tree | b1463fe63d323249b5851ba488ff5d809b77ce80 /src/plugins/platforms/cocoa | |
parent | d7c6d69a8c54d4ac3b6872f619dfefe2c47377b1 (diff) |
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_complextext.mm | 11 |
1 files changed, 9 insertions, 2 deletions
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<QInputMethodEvent::Attribute> 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 |