diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-18 11:31:51 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-19 19:10:58 +0200 |
commit | 4ee20e3a2f4a03f9bda9f43c4e6b41255364690d (patch) | |
tree | ea2dd6772c00085cdc70d09d2845e5d61ed18c0c /src/plugins/platforms/cocoa/qnsview_complextext.mm | |
parent | a5571ec8a0eee6a19d4533113f9ef2e74540cfe7 (diff) |
macOS: Simplify string handling when handling complex text
Pick-to: 6.2
Change-Id: Ib19dab99b836fdd5a5eda5cc54c81f1fea31ce65
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview_complextext.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_complextext.mm | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index 1e5423ab0e..2c2ccc33c8 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -105,14 +105,8 @@ return; } - QString commitString; - if ([aString length]) { - if ([aString isKindOfClass:[NSAttributedString class]]) { - commitString = QString::fromCFString(reinterpret_cast<CFStringRef>([aString string])); - } else { - commitString = QString::fromCFString(reinterpret_cast<CFStringRef>(aString)); - }; - } + const bool isAttributedString = [aString isKindOfClass:NSAttributedString.class]; + QString commitString = QString::fromNSString(isAttributedString ? [aString string] : aString); QObject *focusObject = m_platformWindow->window()->focusObject(); if (queryInputMethod(focusObject)) { @@ -133,14 +127,13 @@ << " with selected range " << selectedRange << ", replacing range " << replacementRange; - QString preeditString; + const bool isAttributedString = [aString isKindOfClass:NSAttributedString.class]; + QString preeditString = QString::fromNSString(isAttributedString ? [aString string] : aString); QList<QInputMethodEvent::Attribute> attrs; attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, selectedRange.location + selectedRange.length, 1, QVariant()); - if ([aString isKindOfClass:[NSAttributedString class]]) { - // Preedit string has attribution - preeditString = QString::fromCFString(reinterpret_cast<CFStringRef>([aString string])); + if (isAttributedString) { int composingLength = preeditString.length(); int index = 0; // Create attributes for individual sections of preedit text @@ -167,9 +160,6 @@ } index = effectiveRange.location + effectiveRange.length; } - } else { - // No attributes specified, take only the preedit text. - preeditString = QString::fromCFString(reinterpret_cast<CFStringRef>(aString)); } if (attrs.isEmpty()) { @@ -207,9 +197,9 @@ if (selectedText.isEmpty()) return nil; - QCFString string(selectedText.mid(aRange.location, aRange.length)); - const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string); - return [[[NSAttributedString alloc] initWithString:const_cast<NSString *>(tmpString)] autorelease]; + NSString *substring = QStringView(selectedText).mid(aRange.location, aRange.length).toNSString(); + return [[[NSAttributedString alloc] initWithString:substring] autorelease]; + } else { return nil; } |