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.10 6.9 6.8
Fixes: QTBUG-136229
Change-Id: I408e6dfd8a91f2d0f1dd8c18dc0dcc2d13cc3e38
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Bartlomiej Moskal 2025-06-03 13:00:26 +02:00
parent 86d843be47
commit a4850d0e0f

View File

@ -66,6 +66,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 {
@ -122,7 +123,7 @@ class QtInputConnection extends BaseInputConnection
void restartImmInput()
{
if (QtNativeInputConnection.fullscreenMode()) {
if (QtNativeInputConnection.fullscreenMode() && !m_duringBatchEdit) {
if (m_imm != null)
m_imm.restartInput(m_view);
}
@ -133,6 +134,7 @@ class QtInputConnection extends BaseInputConnection
public boolean beginBatchEdit()
{
setClosing(false);
m_duringBatchEdit = true;
return QtNativeInputConnection.beginBatchEdit();
}
@ -149,7 +151,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