From 6cece0f43a18dc8c9dbf5bc49ce515714f090725 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Thu, 26 Apr 2018 13:43:45 +0200 Subject: [PATCH] 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. Task-number: QTBUG-67836 Change-Id: Ia83963780fb14b3c571dbbe3eb81fbbe20fbf412 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/widgets/widgets/qwidgettextcontrol.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index d3203e180b..43c1c3e365 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -1977,8 +1977,12 @@ void QWidgetTextControlPrivate::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); @@ -1997,7 +2001,8 @@ void QWidgetTextControlPrivate::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());