Skip to content

Commit 7f8da69

Browse files
agnostic-apollochedim
authored andcommitted
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 termux#867
1 parent 5a2af6f commit 7f8da69

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.os.Build;
1212
import android.os.Handler;
1313
import android.os.Looper;
14+
import android.os.SystemClock;
1415
import android.text.Editable;
1516
import android.text.InputType;
1617
import android.text.TextUtils;
@@ -872,13 +873,36 @@ public boolean handleKeyCode(int keyCode, int keyMod) {
872873
if (mEmulator != null)
873874
mEmulator.setCursorBlinkState(true);
874875

876+
if (handleKeyCodeAction(keyCode, keyMod))
877+
return true;
878+
875879
TerminalEmulator term = mTermSession.getEmulator();
876880
String code = KeyHandler.getCode(keyCode, keyMod, term.isCursorKeysApplicationMode(), term.isKeypadApplicationMode());
877881
if (code == null) return false;
878882
mTermSession.write(code);
879883
return true;
880884
}
881885

886+
public boolean handleKeyCodeAction(int keyCode, int keyMod) {
887+
boolean shiftDown = (keyMod & KeyHandler.KEYMOD_SHIFT) != 0;
888+
889+
switch (keyCode) {
890+
case KeyEvent.KEYCODE_PAGE_UP:
891+
case KeyEvent.KEYCODE_PAGE_DOWN:
892+
// shift+page_up and shift+page_down should scroll scrollback history instead of
893+
// scrolling command history or changing pages
894+
if (shiftDown) {
895+
long time = SystemClock.uptimeMillis();
896+
MotionEvent motionEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
897+
doScroll(motionEvent, keyCode == KeyEvent.KEYCODE_PAGE_UP ? -1 : 1);
898+
motionEvent.recycle();
899+
return true;
900+
}
901+
}
902+
903+
return false;
904+
}
905+
882906
/**
883907
* Called when a key is released in the view.
884908
*

0 commit comments

Comments
 (0)