From 41777fdda61715a59be241f0be9a8e3385222888 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 18 Dec 2025 19:15:32 +0100 Subject: Disable selection mode in text editors (#1141) * Disable selection mode in text editors Selection mode removes the space bar key (which is replaced by the Esc key) and can be annoying in Emacs for example. Text editor users probably have the `esc` key available. * Refactor: Move EditorInfo related code to EditorConfig Add the new EditorConfig class that handles configuration extracted from the EditorInfo. It is accessible from the Config class for convenience. This aims at reducing the length of already large classes and group the code that was spread over several classes.--- srcs/juloo.keyboard2/Autocapitalisation.java | 39 +++++----------------------- 1 file changed, 6 insertions(+), 33 deletions(-) (limited to 'srcs/juloo.keyboard2/Autocapitalisation.java') diff --git a/srcs/juloo.keyboard2/Autocapitalisation.java b/srcs/juloo.keyboard2/Autocapitalisation.java index ec730d5..31d9a7b 100644 --- a/srcs/juloo.keyboard2/Autocapitalisation.java +++ b/srcs/juloo.keyboard2/Autocapitalisation.java @@ -2,8 +2,6 @@ package juloo.keyboard2; import android.os.Handler; import android.text.InputType; -import android.text.TextUtils; -import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.KeyEvent; @@ -22,10 +20,6 @@ public final class Autocapitalisation /** Keep track of the cursor to recognize cursor movements from typing. */ int _cursor; - static int SUPPORTED_CAPS_MODES = - InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | - InputType.TYPE_TEXT_FLAG_CAP_WORDS; - public Autocapitalisation(Handler h, Callback cb) { _handler = h; @@ -37,18 +31,19 @@ public final class Autocapitalisation * [started] does initialisation work and must be called before any other * event. */ - public void started(EditorInfo info, InputConnection ic) + public void started(Config config, InputConnection ic) { _ic = ic; - _caps_mode = info.inputType & TextUtils.CAP_MODE_SENTENCES; - if (!Config.globalConfig().autocapitalisation || _caps_mode == 0) + EditorConfig ec = config.editor_config; + if (!config.autocapitalisation || ec.caps_mode == 0) { _enabled = false; return; } _enabled = true; - _should_enable_shift = (info.initialCapsMode != 0); - _should_update_caps_mode = started_should_update_state(info.inputType); + _caps_mode = ec.caps_mode; + _should_enable_shift = ec.caps_initially_enabled; + _should_update_caps_mode = ec.caps_initially_updated; callback_now(true); } @@ -178,26 +173,4 @@ public final class Autocapitalisation return false; } } - - /** Whether the caps state should be updated when input starts. [inputType] - is the field from the editor info object. */ - boolean started_should_update_state(int inputType) - { - int class_ = inputType & InputType.TYPE_MASK_CLASS; - int variation = inputType & InputType.TYPE_MASK_VARIATION; - if (class_ != InputType.TYPE_CLASS_TEXT) - return false; - switch (variation) - { - case InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE: - case InputType.TYPE_TEXT_VARIATION_NORMAL: - case InputType.TYPE_TEXT_VARIATION_PERSON_NAME: - case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE: - case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT: - case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT: - return true; - default: - return false; - } - } } -- cgit v1.2.3