Fixed: Fix `SHIFT+PAGE_UP` and `SHIFT+PAGE_DOWN` behaviour to scroll `1` line of scrollback history instead of scrolling command history or changing pages

This will work for both `SHIFT` extra key and hardware keyboards. The `SHIFT` extra key can be long held to lock it in an enabled state and `PGUP` and `PGDN` keys can be long held to repeat scrolling.

Closes #867
This commit is contained in:
agnostic-apollo 2023-05-21 07:46:07 +05:00
parent 33295decbb
commit 66a9495d91
1 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import android.graphics.Typeface;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
@ -872,6 +873,9 @@ public final class TerminalView extends View {
if (mEmulator != null)
mEmulator.setCursorBlinkState(true);
if (handleKeyCodeAction(keyCode, keyMod))
return true;
TerminalEmulator term = mTermSession.getEmulator();
String code = KeyHandler.getCode(keyCode, keyMod, term.isCursorKeysApplicationMode(), term.isKeypadApplicationMode());
if (code == null) return false;
@ -879,6 +883,26 @@ public final class TerminalView extends View {
return true;
}
public boolean handleKeyCodeAction(int keyCode, int keyMod) {
boolean shiftDown = (keyMod & KeyHandler.KEYMOD_SHIFT) != 0;
switch (keyCode) {
case KeyEvent.KEYCODE_PAGE_UP:
case KeyEvent.KEYCODE_PAGE_DOWN:
// shift+page_up and shift+page_down should scroll scrollback history instead of
// scrolling command history or changing pages
if (shiftDown) {
long time = SystemClock.uptimeMillis();
MotionEvent motionEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
doScroll(motionEvent, keyCode == KeyEvent.KEYCODE_PAGE_UP ? -1 : 1);
motionEvent.recycle();
return true;
}
}
return false;
}
/**
* Called when a key is released in the view.
*