From 9ef0d2da99f4593d50c16912d00bef121bb76f9b Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Thu, 26 Apr 2018 13:53:54 +0200 Subject: Fix for input method commit that ends with newline If the input method event contains a commit text that ends with a newline, text, the commit string is inserted first. This changes the current block. This change makes sure that we apply the formatting changes (including removing the old preedit text) to the old block in this specific case. This is a copy of change 6cece0f43a18dc8c9dbf5bc49ce515714f090725 in qtbase, since the code is duplicated. Task-number: QTBUG-67836 Change-Id: I531d3f1dce51d840acc0ef7fda9e7affb3192327 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/quick/items/qquicktextcontrol.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index e3080dfe48..1cb12235c1 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -1304,8 +1304,12 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) cursor.removeSelectedText(); } + QTextBlock block; + // insert commit string if (!e->commitString().isEmpty() || e->replacementLength()) { + if (e->commitString().endsWith(QChar::LineFeed)) + block = cursor.block(); // Remember the block where the preedit text is QTextCursor c = cursor; c.setPosition(c.position() + e->replacementStart()); c.setPosition(c.position() + e->replacementLength(), QTextCursor::KeepAnchor); @@ -1324,7 +1328,9 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) } } - QTextBlock block = cursor.block(); + if (!block.isValid()) + block = cursor.block(); + QTextLayout *layout = block.layout(); if (isGettingInput) { layout->setPreeditArea(cursor.position() - block.position(), e->preeditString()); -- cgit v1.2.3