From 39e68b388bebe677c923ca5cf8587c7f0f73a5ba Mon Sep 17 00:00:00 2001 From: Dimo Karaivanov Date: Tue, 22 Aug 2023 10:34:15 +0300 Subject: [PATCH] fixed the cursor moving using touch events not working properly, while typing a word with the physical keys --- src/io/github/sspanak/tt9/ime/TraditionalT9.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/io/github/sspanak/tt9/ime/TraditionalT9.java b/src/io/github/sspanak/tt9/ime/TraditionalT9.java index 9ec90790..f3c05727 100644 --- a/src/io/github/sspanak/tt9/ime/TraditionalT9.java +++ b/src/io/github/sspanak/tt9/ime/TraditionalT9.java @@ -491,6 +491,19 @@ public class TraditionalT9 extends KeyPadHandler { } + @Override + public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd) { + super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd); + + // If the cursor moves while composing a word (usually, because the user has touched the screen outside the word), we must + // end typing end accept the word. Otherwise, the cursor would jump back at the end of the word, after the next key press. + // This is confusing from user perspective, so we want to avoid it. + if (!suggestionBar.isEmpty() && (newSelStart != candidatesEnd || newSelEnd != candidatesEnd)) { + acceptIncompleteSuggestion(); + } + } + + private boolean isSuggestionViewHidden() { return suggestionBar == null || suggestionBar.isEmpty(); }