prevented an unnecessary call to getTextBeforeCursor() when Backspace is pressed
This commit is contained in:
parent
fe4c0bd949
commit
a8b6a0b95a
3 changed files with 20 additions and 10 deletions
|
|
@ -5,10 +5,12 @@ import android.view.KeyEvent;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import io.github.sspanak.tt9.ime.helpers.CursorOps;
|
import io.github.sspanak.tt9.ime.helpers.CursorOps;
|
||||||
|
import io.github.sspanak.tt9.ime.helpers.Key;
|
||||||
import io.github.sspanak.tt9.ime.helpers.SuggestionOps;
|
import io.github.sspanak.tt9.ime.helpers.SuggestionOps;
|
||||||
import io.github.sspanak.tt9.ime.helpers.TextField;
|
import io.github.sspanak.tt9.ime.helpers.TextField;
|
||||||
import io.github.sspanak.tt9.ime.helpers.TextSelection;
|
import io.github.sspanak.tt9.ime.helpers.TextSelection;
|
||||||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||||
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
|
|
||||||
public class AppHacks {
|
public class AppHacks {
|
||||||
private final InputType inputType;
|
private final InputType inputType;
|
||||||
|
|
@ -41,17 +43,19 @@ public class AppHacks {
|
||||||
* Performs extra Backspace operations and returns "false", or completely replaces Backspace and returns "true". When "true" is
|
* Performs extra Backspace operations and returns "false", or completely replaces Backspace and returns "true". When "true" is
|
||||||
* returned, you must not attempt to delete text. This function has already done everything necessary.
|
* returned, you must not attempt to delete text. This function has already done everything necessary.
|
||||||
*/
|
*/
|
||||||
public boolean onBackspace(InputMode inputMode) {
|
public boolean onBackspace(@NonNull SettingsStore settings, @NonNull InputMode inputMode) {
|
||||||
if (inputType.isKindleInvertedTextField()) {
|
if (inputType.isKindleInvertedTextField()) {
|
||||||
inputMode.clearWordStem();
|
inputMode.clearWordStem();
|
||||||
} else if (inputType.isTermux()) {
|
} else if (inputType.isTermux()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When no text is selected and the cursor is at the beginning,
|
// When Backspace function is assigned to a different key (not hardware Backspace), we must
|
||||||
// allow double function keys to function normally (e.g. "Back" navigates back)
|
// allow the key to function normally if there is nothing to delete (e.g. "Back" navigates back).
|
||||||
return
|
return
|
||||||
inputMode.getSuggestions().isEmpty()
|
Key.exists(settings.getKeyBackspace())
|
||||||
|
&& !Key.isHardwareBackspace(settings.getKeyBackspace())
|
||||||
|
&& inputMode.getSuggestions().isEmpty()
|
||||||
&& textSelection.isEmpty()
|
&& textSelection.isEmpty()
|
||||||
&& textField.getStringBeforeCursor(1).isEmpty();
|
&& textField.getStringBeforeCursor(1).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +91,6 @@ public class AppHacks {
|
||||||
/**
|
/**
|
||||||
* Performs extra operations when the cursor moves and returns "true" if the selection was handled,
|
* Performs extra operations when the cursor moves and returns "true" if the selection was handled,
|
||||||
* "false" otherwise.
|
* "false" otherwise.
|
||||||
*
|
|
||||||
* CURSOR RESET
|
* CURSOR RESET
|
||||||
* When sending messages using the Viber or the SMS app SEND button, it does so and clears the text
|
* When sending messages using the Viber or the SMS app SEND button, it does so and clears the text
|
||||||
* field, but without notifying the keyboard. This means, after sending the message, the InputMode
|
* field, but without notifying the keyboard. This means, after sending the message, the InputMode
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ public abstract class TypingHandler extends KeyPadHandler {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appHacks.onBackspace(mInputMode)) {
|
if (appHacks.onBackspace(settings, mInputMode)) {
|
||||||
mInputMode.reset();
|
mInputMode.reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,18 @@ public class Key {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean exists(int keyCode) {
|
||||||
|
return keyCode != KeyEvent.KEYCODE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isBackspace(SettingsStore settings, int keyCode) {
|
public static boolean isBackspace(SettingsStore settings, int keyCode) {
|
||||||
return
|
return isHardwareBackspace(keyCode) || keyCode == settings.getKeyBackspace();
|
||||||
keyCode == KeyEvent.KEYCODE_DEL
|
}
|
||||||
|| keyCode == KeyEvent.KEYCODE_CLEAR
|
|
||||||
|| keyCode == settings.getKeyBackspace();
|
|
||||||
|
public static boolean isHardwareBackspace(int keyCode) {
|
||||||
|
return keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue