Android: fix (partially) text deletion when the cursor is moved

- wait until the handle location changes the cursor position
- don't update cursor position if:
 * a batchEdit is in progress
 * the UpdateSelection is blocked
- finish the composing before update the cursor
- add the missing .java files

There are still corner situations when the text gets deleted/moved, but
those are pretty rare and they will be fix in another patch.

Task-number: QTBUG-57507
Change-Id: I230d7f64625fb556e1be3069694a71e9bc91323a
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
BogDan Vatra 2016-12-08 13:42:16 +02:00 committed by Jani Heikkinen
parent bb0f29f82b
commit 36e4b13e29
4 changed files with 10 additions and 3 deletions

View File

@ -17,7 +17,9 @@ JAVASOURCES += \
$$PATHPREFIX/QtNativeLibrariesDir.java \
$$PATHPREFIX/QtSurface.java \
$$PATHPREFIX/ExtractStyle.java \
$$PATHPREFIX/QtServiceDelegate.java
$$PATHPREFIX/EditMenu.java \
$$PATHPREFIX/EditPopupMenu.java \
$$PATHPREFIX/CursorHandle.java
# install
target.path = $$[QT_INSTALL_PREFIX]/jar

View File

@ -810,7 +810,7 @@ namespace QtAndroidInput
#endif
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();
if (inputContext && qGuiApp)
QMetaObject::invokeMethod(inputContext, "handleLocationChanged",
QMetaObject::invokeMethod(inputContext, "handleLocationChanged", Qt::BlockingQueuedConnection,
Q_ARG(int, id), Q_ARG(int, x), Q_ARG(int, y));
}

View File

@ -578,6 +578,11 @@ void QAndroidInputContext::updateSelectionHandles()
*/
void QAndroidInputContext::handleLocationChanged(int handleId, int x, int y)
{
if (m_batchEditNestingLevel.load() || m_blockUpdateSelection)
return;
finishComposingText();
auto im = qGuiApp->inputMethod();
auto leftRect = im->cursorRectangle();
// The handle is down of the cursor, but we want the position in the middle.

View File

@ -152,7 +152,7 @@ private:
CursorHandleShowPopup = 3
};
CursorHandleShowMode m_cursorHandleShown;
int m_batchEditNestingLevel;
QAtomicInt m_batchEditNestingLevel;
QObject *m_focusObject;
};