diff --git a/docs/user-manual.md b/docs/user-manual.md index 79780938..e93094bd 100644 --- a/docs/user-manual.md +++ b/docs/user-manual.md @@ -61,6 +61,15 @@ _Predictive mode only._ - Clear the suggestion filter, if applied. - When no filter is applied, accept the current word as-is, even if it does not fully match a suggestion, then jump before it. +#### D-pad Center (OK or ENTER): +- When suggestions are displayed, types the currently selected suggestion. +- Otherwise, performs the default action for the current application (e.g. send a message, go to a URL, or just type a new line). + +_**NB:** Every application decides on its own what to do when OK is pressed and TT9 has no control over this._ + +_**NB2:** In messaging applications, you need to enable their "Send with ENTER" or similarly named setting, in order to send messages with OK. If the application has no such setting, it usually means it disallows sending messages this way._ + + #### 0-key: - **In 123 mode:** - **Press:** type "0". diff --git a/src/io/github/sspanak/tt9/ime/TraditionalT9.java b/src/io/github/sspanak/tt9/ime/TraditionalT9.java index edd336d7..c903fe8c 100644 --- a/src/io/github/sspanak/tt9/ime/TraditionalT9.java +++ b/src/io/github/sspanak/tt9/ime/TraditionalT9.java @@ -192,7 +192,7 @@ public class TraditionalT9 extends KeyPadHandler { public boolean onOK() { if (isSuggestionViewHidden() && currentInputConnection != null) { - return sendDefaultEditorAction(false); + return performOKAction(); } String word = mSuggestionView.getCurrentSuggestion(); @@ -601,6 +601,20 @@ public class TraditionalT9 extends KeyPadHandler { } + private boolean performOKAction() { + int action = textField.getAction(); + switch (action) { + case EditorInfo.IME_ACTION_NONE: + return false; + case TextField.IME_ACTION_ENTER: + sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER); + return true; + default: + return currentInputConnection.performEditorAction(action); + } + } + + private void showAddWord() { if (currentInputConnection == null) { return; diff --git a/src/io/github/sspanak/tt9/ime/helpers/TextField.java b/src/io/github/sspanak/tt9/ime/helpers/TextField.java index 64e9d9ae..cad7d9b1 100644 --- a/src/io/github/sspanak/tt9/ime/helpers/TextField.java +++ b/src/io/github/sspanak/tt9/ime/helpers/TextField.java @@ -18,6 +18,8 @@ import io.github.sspanak.tt9.Logger; import io.github.sspanak.tt9.ime.modes.InputMode; public class TextField { + public static final int IME_ACTION_ENTER = EditorInfo.IME_MASK_ACTION + 1; + private static final Pattern beforeCursorWordRegex = Pattern.compile("(\\w+)(?!\n)$"); private static final Pattern afterCursorWordRegex = Pattern.compile("^(? 0) { + return field.actionId; // custom action, defined by the connected app + } + + int standardAction = field.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION); + switch (standardAction) { + case EditorInfo.IME_ACTION_GO: + case EditorInfo.IME_ACTION_NEXT: + case EditorInfo.IME_ACTION_PREVIOUS: + case EditorInfo.IME_ACTION_SEARCH: + case EditorInfo.IME_ACTION_SEND: + return standardAction; + default: + return IME_ACTION_ENTER; + } + } }