diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-27 19:18:36 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-09-06 16:34:51 +0000 |
commit | 25b5c6491f5155a42f855a17bcea0da8957a4978 (patch) | |
tree | 1198ca5b3e9c371854549c9addec957f9f3fe14d | |
parent | 059dcbea2a3f3583c8dfeb14589d429d6799cfa8 (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.
Change-Id: I75b5d8c5403283a0988355e440a98b4df35ec995
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 9877d55a50db45f7c629f2172dd848ef07e9fabe)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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 |