Skip to content

Commit 791bf5f

Browse files
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
1 parent fa710c4 commit 791bf5f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

terminal-view/src/main/java/com/termux/view/TerminalView.java

+24
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.os.Build;
1111
import android.os.Handler;
1212
import android.os.Looper;
13+
import android.os.SystemClock;
1314
import android.text.Editable;
1415
import android.text.InputType;
1516
import android.text.TextUtils;
@@ -839,13 +840,36 @@ public boolean handleKeyCode(int keyCode, int keyMod) {
839840
if (mEmulator != null)
840841
mEmulator.setCursorBlinkState(true);
841842

843+
if (handleKeyCodeAction(keyCode, keyMod))
844+
return true;
845+
842846
TerminalEmulator term = mTermSession.getEmulator();
843847
String code = KeyHandler.getCode(keyCode, keyMod, term.isCursorKeysApplicationMode(), term.isKeypadApplicationMode());
844848
if (code == null) return false;
845849
mTermSession.write(code);
846850
return true;
847851
}
848852

853+
public boolean handleKeyCodeAction(int keyCode, int keyMod) {
854+
boolean shiftDown = (keyMod & KeyHandler.KEYMOD_SHIFT) != 0;
855+
856+
switch (keyCode) {
857+
case KeyEvent.KEYCODE_PAGE_UP:
858+
case KeyEvent.KEYCODE_PAGE_DOWN:
859+
// shift+page_up and shift+page_down should scroll scrollback history instead of
860+
// scrolling command history or changing pages
861+
if (shiftDown) {
862+
long time = SystemClock.uptimeMillis();
863+
MotionEvent motionEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
864+
doScroll(motionEvent, keyCode == KeyEvent.KEYCODE_PAGE_UP ? -1 : 1);
865+
motionEvent.recycle();
866+
return true;
867+
}
868+
}
869+
870+
return false;
871+
}
872+
849873
/**
850874
* Called when a key is released in the view.
851875
*

0 commit comments

Comments
 (0)