abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorJules Aguillon2023-09-09 14:15:44 +0200
committerJules Aguillon2023-09-09 14:15:44 +0200
commit92a8db5e9374082000f9c79becd09661bea84dd9 (patch)
tree8b6d43d3c3068653887c8247fdc29abf652bf3da
parent687d88f4f767190d2d60fe104a140381b6652d18 (diff)
downloadunexpected-keyboard-92a8db5e9374082000f9c79becd09661bea84dd9.tar.gz
unexpected-keyboard-92a8db5e9374082000f9c79becd09661bea84dd9.zip
Update auto-capitalisation state when input starts
The initial capitalisation state given by the editor (`info.initialCapsMode`) is always 0 in many editors. For some text input types, update the state when typing starts, disregarding the value given by `info.initialCapsMode`.
-rw-r--r--srcs/juloo.keyboard2/Autocapitalisation.java40
1 files changed, 37 insertions, 3 deletions
diff --git a/srcs/juloo.keyboard2/Autocapitalisation.java b/srcs/juloo.keyboard2/Autocapitalisation.java
index 3dcdefc..b73f2e3 100644
--- a/srcs/juloo.keyboard2/Autocapitalisation.java
+++ b/srcs/juloo.keyboard2/Autocapitalisation.java
@@ -49,7 +49,8 @@ final class Autocapitalisation
}
_enabled = true;
_should_enable_shift = (info.initialCapsMode != 0);
- _callback.update_shift_state(_should_enable_shift, true);
+ _should_update_caps_mode = started_should_update_state(info.inputType);
+ callback_now(true);
}
public void typed(CharSequence c)
@@ -81,7 +82,7 @@ final class Autocapitalisation
{
_should_enable_shift = false;
_should_update_caps_mode = false;
- callback(true);
+ callback_now(true);
}
public static interface Callback
@@ -119,7 +120,11 @@ final class Autocapitalisation
}
};
- void callback(final boolean might_disable)
+ /** Update the shift state if [_should_update_caps_mode] is true, then call
+ [_callback.update_shift_state]. This is done after a short delay to wait
+ for the editor to handle the events, as this might be called before the
+ corresponding event is sent. */
+ void callback(boolean might_disable)
{
_should_disable_shift = might_disable;
// The callback must be delayed because [getCursorCapsMode] would sometimes
@@ -127,6 +132,13 @@ final class Autocapitalisation
_handler.postDelayed(delayed_callback, 1);
}
+ /** Like [callback] but runs immediately. */
+ void callback_now(boolean might_disable)
+ {
+ _should_disable_shift = might_disable;
+ delayed_callback.run();
+ }
+
void type_one_char(char c)
{
_cursor++;
@@ -146,4 +158,26 @@ 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;
+ }
+ }
}