More precise and faster spacebar slider (#593)

* Make slider speed independent from swipe distance

Swipe distances other than the default resulted in a slider that were
not easy to control.

* refactor: Add class Pointers.Sliding

It holds the states and the code needed to make the slider work.
'Pointer.sliding' is set to [null] when sliding is not in progress.

The implementation is changed not to depend on [downX] and [dx] but
instead use the pointer's [x] coordinate directly.

* Move the cursor further for faster slides

In sliding mode, compute the speed of the pointer and use it to increase
at which the cursor moves.

* refactor: Separate kind for cursor movement keys

This allows to define a key that moves the cursor more than one position
at a time.

This will be used to avoid lag during fast slider movements.

* Reduce lag when sliding quickly on the spacebar

Avoid sending key events in a loop while sliding quickly in a cursor
movement key. Key of kind Cursor_move are "multiplied", meaning a single
key event represents a movement of more than one position, reducing the
number of key events sent.
This is only for cursor move keys.
This commit is contained in:
Jules Aguillon
2024-05-02 19:31:48 +02:00
committed by GitHub
parent 82e0840568
commit 0f11a88418
4 changed files with 119 additions and 44 deletions

View File

@@ -71,8 +71,6 @@ public final class KeyValue implements Comparable<KeyValue>
SHARE,
ASSIST,
AUTOFILL,
CURSOR_LEFT,
CURSOR_RIGHT,
}
public static enum Placeholder
@@ -89,7 +87,8 @@ public final class KeyValue implements Comparable<KeyValue>
public static enum Kind
{
Char, String, Keyevent, Event, Compose_pending, Modifier, Editing,
Placeholder
Placeholder,
Cursor_move // Value is encoded as a 16-bit integer
}
private static final int FLAGS_OFFSET = 19;
@@ -196,6 +195,12 @@ public final class KeyValue implements Comparable<KeyValue>
return (_code & VALUE_BITS);
}
/** Defined only when [getKind() == Kind.Cursor_move]. */
public short getCursorMove()
{
return (short)(_code & VALUE_BITS);
}
/* Update the char and the symbol. */
public KeyValue withChar(char c)
{
@@ -325,6 +330,16 @@ public final class KeyValue implements Comparable<KeyValue>
return editingKey(String.valueOf((char)symbol), action, FLAG_KEY_FONT);
}
/** A key that moves the cursor [d] times to the right. If [d] is negative,
it moves the cursor [abs(d)] times to the left. */
public static KeyValue cursorMoveKey(int d)
{
int symbol = (d < 0) ? 0xE008 : 0xE006;
return new KeyValue(String.valueOf((char)symbol), Kind.Cursor_move,
((short)d) & 0xFFFF,
FLAG_SPECIAL | FLAG_SECONDARY | FLAG_KEY_FONT);
}
/** A key that do nothing but has a unique ID. */
private static KeyValue placeholderKey(Placeholder id)
{
@@ -507,8 +522,8 @@ public final class KeyValue implements Comparable<KeyValue>
case "pasteAsPlainText": return editingKey(0xE035, Editing.PASTE_PLAIN);
case "undo": return editingKey(0xE036, Editing.UNDO);
case "redo": return editingKey(0xE037, Editing.REDO);
case "cursor_left": return editingKey(0xE008, Editing.CURSOR_LEFT);
case "cursor_right": return editingKey(0xE006, Editing.CURSOR_RIGHT);
case "cursor_left": return cursorMoveKey(-1);
case "cursor_right": return cursorMoveKey(1);
// These keys are not used
case "replaceText": return editingKey("repl", Editing.REPLACE);
case "textAssist": return editingKey(0xE038, Editing.ASSIST);