summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wayland/qwaylandtextinputv3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/wayland/qwaylandtextinputv3.cpp')
-rw-r--r--src/plugins/platforms/wayland/qwaylandtextinputv3.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/plugins/platforms/wayland/qwaylandtextinputv3.cpp b/src/plugins/platforms/wayland/qwaylandtextinputv3.cpp
index fbb40c2e216..42ee5cde2ff 100644
--- a/src/plugins/platforms/wayland/qwaylandtextinputv3.cpp
+++ b/src/plugins/platforms/wayland/qwaylandtextinputv3.cpp
@@ -309,7 +309,8 @@ void QWaylandTextInputv3::updateState(Qt::InputMethodQueries queries, uint32_t f
// The worst case will be supposed here.
const int MAX_MESSAGE_SIZE = 4000;
- const int textSize = text.toUtf8().size();
+ const QByteArray utf8 = text.toUtf8();
+ const int textSize = utf8.size();
if (textSize > MAX_MESSAGE_SIZE) {
qCDebug(qLcQpaWaylandTextInput) << "SurroundText size is over "
<< MAX_MESSAGE_SIZE
@@ -317,18 +318,19 @@ void QWaylandTextInputv3::updateState(Qt::InputMethodQueries queries, uint32_t f
const int selectionStart = qMin(cursor, anchor);
const int selectionEnd = qMax(cursor, anchor);
const int selectionLength = selectionEnd - selectionStart;
- const int selectionSize = QStringView{text}.sliced(selectionStart, selectionLength).toUtf8().size();
+ QByteArray selection = QStringView{text}.sliced(selectionStart, selectionLength).toUtf8();
+ const int selectionSize = selection.size();
// If selection is bigger than 4000 byte, it is fixed to 4000 byte.
// anchor will be moved in the 4000 byte boundary.
if (selectionSize > MAX_MESSAGE_SIZE) {
if (anchor > cursor) {
cursor = 0;
anchor = MAX_MESSAGE_SIZE;
- text = text.sliced(selectionStart, selectionLength);
+ text = QString::fromUtf8(QByteArrayView{selection}.sliced(0, MAX_MESSAGE_SIZE));
} else {
anchor = 0;
cursor = MAX_MESSAGE_SIZE;
- text = text.sliced(selectionEnd - selectionLength, selectionLength);
+ text = QString::fromUtf8(QByteArrayView{selection}.sliced(selectionSize - MAX_MESSAGE_SIZE, MAX_MESSAGE_SIZE));
}
} else {
// This is not optimal in some cases.
@@ -340,10 +342,10 @@ void QWaylandTextInputv3::updateState(Qt::InputMethodQueries queries, uint32_t f
cursor = QWaylandInputMethodEventBuilder::indexToWayland(text, cursor);
anchor = QWaylandInputMethodEventBuilder::indexToWayland(text, anchor);
if (selEndSize < MAX_MESSAGE_SIZE) {
- text = QString::fromUtf8(QByteArrayView{text.toUtf8()}.first(MAX_MESSAGE_SIZE));
+ text = QString::fromUtf8(QByteArrayView{utf8}.first(MAX_MESSAGE_SIZE));
} else {
const int startOffset = selEndSize - MAX_MESSAGE_SIZE;
- text = QString::fromUtf8(QByteArrayView{text.toUtf8()}.sliced(startOffset, MAX_MESSAGE_SIZE));
+ text = QString::fromUtf8(QByteArrayView{utf8}.sliced(startOffset, MAX_MESSAGE_SIZE));
cursor -= startOffset;
anchor -= startOffset;
}