Android: Avoid restarting InputMethodManager during IME batch edits

beginBatchEdit() means the start of a batch of related input operations
from the Input Method Editor. We should not restart input until
endBatchEdit() is called. Restarting it before may cause issue with
inactive InputConnection.

This commit fixes an issue where calling
InputMethodManager.restartInput() during a batch edit (e.g., between
beginBatchEdit and endBatchEdit).

Pick-to: 6.8
Fixes: QTBUG-136229
Change-Id: I408e6dfd8a91f2d0f1dd8c18dc0dcc2d13cc3e38
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit a4850d0e0f42229afe2af10cee5794d0de70416c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit ddd53192d348d2c2751ca3b492bead42619f8200)
This commit is contained in:
Bartlomiej Moskal 2025-06-03 13:00:26 +02:00 committed by Qt Cherry-pick Bot
parent 35f2704d20
commit 9b85022d56

View File

@ -70,6 +70,7 @@ class QtInputConnection extends BaseInputConnection
private static final String QtTAG = "QtInputConnection";
private boolean m_duringBatchEdit = false;
private final QtInputConnectionListener m_qtInputConnectionListener;
class HideKeyboardRunnable implements Runnable {
@ -126,7 +127,7 @@ class QtInputConnection extends BaseInputConnection
void restartImmInput()
{
if (QtNativeInputConnection.fullscreenMode()) {
if (QtNativeInputConnection.fullscreenMode() && !m_duringBatchEdit) {
if (m_imm != null)
m_imm.restartInput(m_view);
}
@ -137,6 +138,7 @@ class QtInputConnection extends BaseInputConnection
public boolean beginBatchEdit()
{
setClosing(false);
m_duringBatchEdit = true;
return QtNativeInputConnection.beginBatchEdit();
}
@ -153,7 +155,12 @@ class QtInputConnection extends BaseInputConnection
public boolean endBatchEdit()
{
setClosing(false);
return QtNativeInputConnection.endBatchEdit();
boolean ret = QtNativeInputConnection.endBatchEdit();
if (m_duringBatchEdit) {
m_duringBatchEdit = false;
restartImmInput();
}
return ret;
}
@Override