no unnecessary automatic space, when there is already a space after the cursor
This commit is contained in:
parent
b7c08928c9
commit
8888485f70
4 changed files with 17 additions and 4 deletions
|
|
@ -28,6 +28,16 @@ public class InputFieldHelper {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* isThereSpaceAhead
|
||||
* Checks whether there is a space after the cursor.
|
||||
*/
|
||||
public static boolean isThereSpaceAhead(InputConnection inputConnection) {
|
||||
CharSequence after = inputConnection != null ? inputConnection.getTextAfterCursor(1, 0) : null;
|
||||
return after != null && after.equals(" ");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* isDialerField
|
||||
* Dialer fields seem to take care of numbers and backspace on their own,
|
||||
|
|
|
|||
|
|
@ -554,7 +554,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
InputFieldHelper.deletePrecedingSpace(currentInputConnection, currentWord);
|
||||
}
|
||||
|
||||
if (mInputMode.shouldAddAutoSpace(inputField, isWordAcceptedManually, incomingKey, hold)) {
|
||||
if (mInputMode.shouldAddAutoSpace(currentInputConnection, inputField, isWordAcceptedManually, incomingKey, hold)) {
|
||||
commitText(" ");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package io.github.sspanak.tt9.ime.modes;
|
|||
|
||||
import android.os.Handler;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ abstract public class InputMode {
|
|||
abstract public int getId();
|
||||
abstract public int getSequenceLength(); // The number of key presses for the current word.
|
||||
|
||||
public boolean shouldAddAutoSpace(EditorInfo inputField, boolean isWordAcceptedManually, int incomingKey, boolean hold) { return false; }
|
||||
public boolean shouldAddAutoSpace(InputConnection inputConnection, EditorInfo inputField, boolean isWordAcceptedManually, int incomingKey, boolean hold) { return false; }
|
||||
public boolean shouldDeletePrecedingSpace(EditorInfo inputField) { return false; }
|
||||
|
||||
public void reset() {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.os.Handler;
|
|||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -116,14 +117,15 @@ public class ModePredictive extends InputMode {
|
|||
* See the helper functions for the list of rules.
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldAddAutoSpace(EditorInfo inputField, boolean isWordAcceptedManually, int incomingKey, boolean hold) {
|
||||
public boolean shouldAddAutoSpace(InputConnection inputConnection, EditorInfo inputField, boolean isWordAcceptedManually, int incomingKey, boolean hold) {
|
||||
return
|
||||
settings.getAutoSpace()
|
||||
&& !hold
|
||||
&& (
|
||||
shouldAddAutoSpaceAfterPunctuation(inputField, incomingKey)
|
||||
|| shouldAddAutoSpaceAfterWord(inputField, isWordAcceptedManually)
|
||||
);
|
||||
)
|
||||
&& !InputFieldHelper.isThereSpaceAhead(inputConnection);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue