diff --git a/src/inputpanel/QskInputPanel.cpp b/src/inputpanel/QskInputPanel.cpp index 90009d37..a735aecc 100644 --- a/src/inputpanel/QskInputPanel.cpp +++ b/src/inputpanel/QskInputPanel.cpp @@ -26,23 +26,6 @@ static inline bool qskUsePrediction( Qt::InputMethodHints hints ) return ( hints & mask ) == 0; } -static inline void qskSendReplaceText( QQuickItem* receiver, const QString& text ) -{ - if ( receiver == nullptr ) - return; - - QInputMethodEvent::Attribute attribute( - QInputMethodEvent::Selection, 0, 32767, QVariant() ); - - QInputMethodEvent event1( QString(), { attribute } ); - QCoreApplication::sendEvent( receiver, &event1 ); - - QInputMethodEvent event2; - event2.setCommitString( text ); - - QCoreApplication::sendEvent( receiver, &event2 ); -} - static inline void qskSendText( QQuickItem* receiver, const QString& text, bool isFinal ) { @@ -52,7 +35,16 @@ static inline void qskSendText( QQuickItem* receiver, if ( isFinal ) { QInputMethodEvent event; - event.setCommitString( text ); + + /* + QQuickTextInput is buggy when receiving empty + empty commit strings. We need to send a wrong + replaceLength to work around it. See QTBUG: 68874 + */ + if ( text.isEmpty() ) + event.setCommitString( text, 0, 1 ); + else + event.setCommitString( text ); QCoreApplication::sendEvent( receiver, &event ); } @@ -70,6 +62,21 @@ static inline void qskSendText( QQuickItem* receiver, } } +static inline void qskSendReplaceText( QQuickItem* receiver, const QString& text ) +{ + if ( receiver == nullptr ) + return; + + QInputMethodEvent::Attribute attribute( + QInputMethodEvent::Selection, 0, 32767, QVariant() ); + + QInputMethodEvent event( QString(), { attribute } ); + QCoreApplication::sendEvent( receiver, &event ); + + qskSendText( receiver, text, true ); +} + + static inline void qskSendKey( QQuickItem* receiver, int key ) { if ( receiver == nullptr )