forked from extern/Unexpected-Keyboard
Avoid automatic capitalisation when using arrows
Disable capitalisation just after an arrow kind is pressed to avoid interrupting navigation.
This commit is contained in:
parent
324756535e
commit
bfde31da6e
@ -10,7 +10,8 @@ final class Autocapitalisation
|
|||||||
{
|
{
|
||||||
private boolean _enabled = false;
|
private boolean _enabled = false;
|
||||||
private boolean _beginning_of_sentence = false;
|
private boolean _beginning_of_sentence = false;
|
||||||
|
/** Used to avoid enabling shift after an arrow key is pressed. */
|
||||||
|
private boolean _skip_next_selection_update = false;
|
||||||
/** Keep track of the cursor to differentiate 'selection_updated' events
|
/** Keep track of the cursor to differentiate 'selection_updated' events
|
||||||
corresponding to typing from cursor movement. */
|
corresponding to typing from cursor movement. */
|
||||||
private int _cursor = 0;
|
private int _cursor = 0;
|
||||||
@ -50,22 +51,50 @@ final class Autocapitalisation
|
|||||||
_beginning_of_sentence = false;
|
_beginning_of_sentence = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selection_updated(int old_cursor, int new_cursor, InputConnection ic)
|
public void event_sent(int code)
|
||||||
{
|
{
|
||||||
|
switch (code)
|
||||||
|
{
|
||||||
|
// Disable temporarily after a keyboard cursor movement
|
||||||
|
case KeyEvent.KEYCODE_DPAD_UP:
|
||||||
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||||
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||||
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||||
|
case KeyEvent.KEYCODE_PAGE_UP:
|
||||||
|
case KeyEvent.KEYCODE_PAGE_DOWN:
|
||||||
|
case KeyEvent.KEYCODE_MOVE_HOME:
|
||||||
|
case KeyEvent.KEYCODE_MOVE_END:
|
||||||
|
_skip_next_selection_update = true;
|
||||||
|
_beginning_of_sentence = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns [true] if shift might be disabled. */
|
||||||
|
public boolean selection_updated(int old_cursor, int new_cursor, InputConnection ic)
|
||||||
|
{
|
||||||
|
if (_skip_next_selection_update)
|
||||||
|
{
|
||||||
|
_cursor = new_cursor;
|
||||||
|
_skip_next_selection_update = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (new_cursor == _cursor)
|
if (new_cursor == _cursor)
|
||||||
return;
|
return false;
|
||||||
// Text has been inserted
|
// Text has been inserted or cursor moved forward
|
||||||
if (old_cursor == _cursor && new_cursor > old_cursor)
|
if (old_cursor == _cursor && new_cursor > old_cursor)
|
||||||
{
|
{
|
||||||
scan_text_before_cursor(Math.min(new_cursor - old_cursor, 10), ic);
|
scan_text_before_cursor(Math.min(new_cursor - old_cursor, 10), ic);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Cursor has moved or [_cursor] wasn't uptodate
|
// Cursor has moved backward or text deleted
|
||||||
_beginning_of_sentence = false;
|
_beginning_of_sentence = false;
|
||||||
scan_text_before_cursor(10, ic);
|
scan_text_before_cursor(10, ic);
|
||||||
|
_cursor = new_cursor;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
_cursor = new_cursor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates [_cursor]. */
|
/** Updates [_cursor]. */
|
||||||
|
@ -251,8 +251,8 @@ public class Keyboard2 extends InputMethodService
|
|||||||
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd)
|
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd)
|
||||||
{
|
{
|
||||||
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);
|
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);
|
||||||
_autocap.selection_updated(oldSelStart, newSelStart, getCurrentInputConnection());
|
update_shift_state(
|
||||||
update_shift_state(true);
|
_autocap.selection_updated(oldSelStart, newSelStart, getCurrentInputConnection()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -337,6 +337,11 @@ public class Keyboard2 extends InputMethodService
|
|||||||
if (conn == null)
|
if (conn == null)
|
||||||
return;
|
return;
|
||||||
conn.sendKeyEvent(new KeyEvent(1, 1, eventAction, eventCode, 0, meta));
|
conn.sendKeyEvent(new KeyEvent(1, 1, eventAction, eventCode, 0, meta));
|
||||||
|
if (eventAction == KeyEvent.ACTION_UP)
|
||||||
|
{
|
||||||
|
_autocap.event_sent(eventCode);
|
||||||
|
update_shift_state(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showKeyboardConfig()
|
public void showKeyboardConfig()
|
||||||
|
Loading…
Reference in New Issue
Block a user