mirror of https://github.com/termux/termux-app
Added: Add `SCROLL` extra key to toggle auto scrolling of terminal to bottom on terminal text updates and termux activity return
The toggle will apply to each terminal session separately. Closes #2535
This commit is contained in:
parent
a2df7d791a
commit
5fc2b4cd4a
|
@ -96,6 +96,10 @@ public class TermuxTerminalExtraKeys extends TerminalExtraKeys {
|
||||||
} else if ("PASTE".equals(key)) {
|
} else if ("PASTE".equals(key)) {
|
||||||
if(mTermuxTerminalSessionActivityClient != null)
|
if(mTermuxTerminalSessionActivityClient != null)
|
||||||
mTermuxTerminalSessionActivityClient.onPasteTextFromClipboard(null);
|
mTermuxTerminalSessionActivityClient.onPasteTextFromClipboard(null);
|
||||||
|
} else if ("SCROLL".equals(key)) {
|
||||||
|
TerminalView terminalView = mTermuxTerminalViewClient.getActivity().getTerminalView();
|
||||||
|
if (terminalView != null && terminalView.mEmulator != null)
|
||||||
|
terminalView.mEmulator.toggleAutoScrollDisabled();
|
||||||
} else {
|
} else {
|
||||||
super.onTerminalExtraKeyButtonClick(view, key, ctrlDown, altDown, shiftDown, fnDown);
|
super.onTerminalExtraKeyButtonClick(view, key, ctrlDown, altDown, shiftDown, fnDown);
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,6 +252,9 @@ public final class TerminalEmulator {
|
||||||
*/
|
*/
|
||||||
private int mScrollCounter = 0;
|
private int mScrollCounter = 0;
|
||||||
|
|
||||||
|
/** If automatic scrolling of terminal is disabled */
|
||||||
|
private boolean mAutoScrollDisabled;
|
||||||
|
|
||||||
private byte mUtf8ToFollow, mUtf8Index;
|
private byte mUtf8ToFollow, mUtf8Index;
|
||||||
private final byte[] mUtf8InputBuffer = new byte[4];
|
private final byte[] mUtf8InputBuffer = new byte[4];
|
||||||
private int mLastEmittedCodePoint = -1;
|
private int mLastEmittedCodePoint = -1;
|
||||||
|
@ -2412,6 +2415,15 @@ public final class TerminalEmulator {
|
||||||
mScrollCounter = 0;
|
mScrollCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAutoScrollDisabled() {
|
||||||
|
return mAutoScrollDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleAutoScrollDisabled() {
|
||||||
|
mAutoScrollDisabled = !mAutoScrollDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Reset terminal state so user can interact with it regardless of present state. */
|
/** Reset terminal state so user can interact with it regardless of present state. */
|
||||||
public void reset() {
|
public void reset() {
|
||||||
setCursorStyle();
|
setCursorStyle();
|
||||||
|
|
|
@ -409,19 +409,29 @@ public final class TerminalView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onScreenUpdated() {
|
public void onScreenUpdated() {
|
||||||
|
onScreenUpdated(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onScreenUpdated(boolean skipScrolling) {
|
||||||
if (mEmulator == null) return;
|
if (mEmulator == null) return;
|
||||||
|
|
||||||
int rowsInHistory = mEmulator.getScreen().getActiveTranscriptRows();
|
int rowsInHistory = mEmulator.getScreen().getActiveTranscriptRows();
|
||||||
if (mTopRow < -rowsInHistory) mTopRow = -rowsInHistory;
|
if (mTopRow < -rowsInHistory) mTopRow = -rowsInHistory;
|
||||||
|
|
||||||
boolean skipScrolling = false;
|
if (isSelectingText() || mEmulator.isAutoScrollDisabled()) {
|
||||||
if (isSelectingText()) {
|
|
||||||
// Do not scroll when selecting text.
|
// Do not scroll when selecting text.
|
||||||
int rowShift = mEmulator.getScrollCounter();
|
int rowShift = mEmulator.getScrollCounter();
|
||||||
if (-mTopRow + rowShift > rowsInHistory) {
|
if (-mTopRow + rowShift > rowsInHistory) {
|
||||||
// .. unless we're hitting the end of history transcript, in which
|
// .. unless we're hitting the end of history transcript, in which
|
||||||
// case we abort text selection and scroll to end.
|
// case we abort text selection and scroll to end.
|
||||||
stopTextSelectionMode();
|
if (isSelectingText())
|
||||||
|
stopTextSelectionMode();
|
||||||
|
|
||||||
|
if (mEmulator.isAutoScrollDisabled()) {
|
||||||
|
mTopRow = -rowsInHistory;
|
||||||
|
skipScrolling = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
skipScrolling = true;
|
skipScrolling = true;
|
||||||
mTopRow -= rowShift;
|
mTopRow -= rowShift;
|
||||||
|
|
|
@ -90,6 +90,7 @@ public class ExtraKeysConstants {
|
||||||
put("DRAWER", "☰"); // U+2630 ☰ TRIGRAM FOR HEAVEN not well known but easy to understand
|
put("DRAWER", "☰"); // U+2630 ☰ TRIGRAM FOR HEAVEN not well known but easy to understand
|
||||||
put("KEYBOARD", "⌨"); // U+2328 ⌨ KEYBOARD not well known but easy to understand
|
put("KEYBOARD", "⌨"); // U+2328 ⌨ KEYBOARD not well known but easy to understand
|
||||||
put("PASTE", "⎘"); // U+2398
|
put("PASTE", "⎘"); // U+2398
|
||||||
|
put("SCROLL", "⇳"); // U+21F3
|
||||||
}};
|
}};
|
||||||
|
|
||||||
public static final ExtraKeyDisplayMap LESS_KNOWN_CHARACTERS_DISPLAY = new ExtraKeyDisplayMap() {{
|
public static final ExtraKeyDisplayMap LESS_KNOWN_CHARACTERS_DISPLAY = new ExtraKeyDisplayMap() {{
|
||||||
|
|
Loading…
Reference in New Issue