From 7f147cf30e8c72ed4c452de31f4b5f853dbe9e4f Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 23 Mar 2009 13:13:43 +0100 Subject: Don't commit an empty string to the widget when it looses focus. When a wiget that accepts keyboard input looses focus and the input context is resetted we should clear the old preedit string by sending an empty commit string only if the widget received non-empty pre-edit string before. Reviewed-by: Brad --- src/gui/inputmethod/qximinputcontext_p.h | 1 + src/gui/inputmethod/qximinputcontext_x11.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/inputmethod/qximinputcontext_p.h b/src/gui/inputmethod/qximinputcontext_p.h index ca2103b..3773122 100644 --- a/src/gui/inputmethod/qximinputcontext_p.h +++ b/src/gui/inputmethod/qximinputcontext_p.h @@ -98,6 +98,7 @@ public: QString text; QBitArray selectedChars; bool composing; + bool preeditEmpty; void clear(); }; diff --git a/src/gui/inputmethod/qximinputcontext_x11.cpp b/src/gui/inputmethod/qximinputcontext_x11.cpp index 48a96b1..1c8560f 100644 --- a/src/gui/inputmethod/qximinputcontext_x11.cpp +++ b/src/gui/inputmethod/qximinputcontext_x11.cpp @@ -264,6 +264,7 @@ extern "C" { qic->standardFormat(QInputContext::PreeditFormat)); attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, sellen ? 0 : 1, QVariant()); QInputMethodEvent e(data->text, attrs); + data->preeditEmpty = data->text.isEmpty(); qic->sendEvent(e); return 0; @@ -286,6 +287,7 @@ void QXIMInputContext::ICData::clear() text = QString(); selectedChars.clear(); composing = false; + preeditEmpty = true; } QXIMInputContext::ICData *QXIMInputContext::icData() const @@ -537,9 +539,12 @@ void QXIMInputContext::reset() if (mb) { e.setCommitString(QString::fromLocal8Bit(mb)); XFree(mb); + data->preeditEmpty = false; // force sending an event + } + if (!data->preeditEmpty) { + sendEvent(e); + update(); } - sendEvent(e); - update(); } data->clear(); } @@ -686,6 +691,7 @@ QXIMInputContext::ICData *QXIMInputContext::createICData(QWidget *w) { ICData *data = new ICData; data->widget = w; + data->preeditEmpty = true; XVaNestedList preedit_attr = 0; XIMCallback startcallback, drawcallback, donecallback; -- cgit v0.12