mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 05:52:47 +00:00
Add support for vertical cursor movement using the spacebar (#486)
--------- Co-authored-by: Helium314 <helium314@disroot.org>
This commit is contained in:
parent
1ffa4766af
commit
4b78546e97
8 changed files with 155 additions and 58 deletions
|
@ -1389,8 +1389,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onMovePointer(int steps) {
|
||||
if (steps == 0) return;
|
||||
public boolean onHorizontalSpaceSwipe(final int steps) {
|
||||
return switch (mSettings.getCurrent().mSpaceSwipeHorizontal) {
|
||||
case KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorHorizontally(steps);
|
||||
case KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps);
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean onMoveCursorHorizontally(int steps) {
|
||||
if (steps == 0) return false;
|
||||
// for RTL languages we want to invert pointer movement
|
||||
if (mRichImm.getCurrentSubtype().isRtlSubtype())
|
||||
steps = -steps;
|
||||
|
@ -1406,7 +1414,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
onCodeInput(KeyCode.ARROW_LEFT, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false);
|
||||
++steps;
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
int availableCharacters = mInputLogic.mConnection.getTextAfterCursor(64, 0).length();
|
||||
|
@ -1416,7 +1424,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
onCodeInput(KeyCode.ARROW_RIGHT, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false);
|
||||
--steps;
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1425,12 +1433,44 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
// this is a noticeable performance improvement
|
||||
int newPosition = mInputLogic.mConnection.mExpectedSelStart + moveSteps;
|
||||
mInputLogic.mConnection.setSelection(newPosition, newPosition);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
mInputLogic.finishInput();
|
||||
int newPosition = mInputLogic.mConnection.mExpectedSelStart + moveSteps;
|
||||
mInputLogic.mConnection.setSelection(newPosition, newPosition);
|
||||
mInputLogic.restartSuggestionsOnWordTouchedByCursor(mSettings.getCurrent(), mKeyboardSwitcher.getCurrentKeyboardScript());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onVerticalSpaceSwipe(final int steps) {
|
||||
return switch (mSettings.getCurrent().mSpaceSwipeVertical) {
|
||||
case KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorVertically(steps);
|
||||
case KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps);
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean onLanguageSlide(final int steps) {
|
||||
if (Math.abs(steps) < 4)
|
||||
return false;
|
||||
List<InputMethodSubtype> subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypeList(false);
|
||||
if (subtypes.size() <= 1) { // only allow if we have more than one subtype
|
||||
return false;
|
||||
}
|
||||
// decide next or previous dependent on up or down
|
||||
InputMethodSubtype current = RichInputMethodManager.getInstance().getCurrentSubtype().getRawSubtype();
|
||||
int wantedIndex = (subtypes.indexOf(current) + ((steps > 0) ? 1 : -1)) % subtypes.size();
|
||||
if (wantedIndex < 0) wantedIndex += subtypes.size();
|
||||
KeyboardSwitcher.getInstance().switchToSubtype(subtypes.get(wantedIndex));
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean onMoveCursorVertically(int steps) {
|
||||
if (steps == 0) return false;
|
||||
int code = (steps < 0) ? KeyCode.ARROW_UP : KeyCode.ARROW_DOWN;
|
||||
onCodeInput(code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue