Skip to content

Changed(terminal-view): Anchor scrollback to document rows and use OverScroller sub-pixel scrolling - #5443

Open
qwerty123yucy wants to merge 1 commit into
termux:masterfrom
qwerty123yucy:pr/anchored-overscroller
Open

qwerty123yucy wants to merge 1 commit into
termux:masterfrom
qwerty123yucy:pr/anchored-overscroller

Conversation

@qwerty123yucy

@qwerty123yucy qwerty123yucy commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

  1. Viewport jumps while reading scrollback during active output:
    TerminalView tracks the scroll position as an integer row offset mTopRow relative to the bottom screen (0 = top of screen, -N = N rows into transcript). Unless terminal-autoscroll-toggle is manually engaged beforehand, scrolling up into history immediately snaps back to 0 on the next output byte; and even when pinned, tracking via mScrollCounter shifts only on UI updates and resets abruptly once the circular transcript buffer wraps.
  2. Whole-row step quantization during touch drag and fling:
    TerminalView uses integer row deltas (Scroller in row units + mScrollRemainder) and draws rows strictly at integer multiples of mFontLineSpacing, producing line-stepped judder during slow finger drags and coasting flings on high-refresh-rate displays.

Changes

  • Document-anchored scrollback (TerminalBuffer & TerminalEmulator):
    • Track monotonic mBaseAbsoluteRow in TerminalBuffer corresponding to external row 0 (mScreenFirstRow) across line scrolls and row/column resizes.
    • Track mAnchoredDocRow and mFollowOutput in TerminalEmulator (pinViewportToBottom(), freezeViewportAtOffset(), setViewportOffset(), getViewportOffset()):
      • Behavior change: Scrolling up into scrollback history automatically anchors the viewport to that document row (mFollowOutput = false) while new output streams below, without requiring mAutoScrollDisabled to be toggled first; if circular buffer wraparound eventually reaches the anchored row, getViewportOffset() clamps at -rowsInHistory instead of snapping to 0. Scrolling back to the bottom or typing user input re-engages live output following (mFollowOutput = true).
      • CSI 3 J / RIS reset: When a program clears the scrollback buffer via CSI 3 J (clearTranscript()) or RIS (ESC c), mBaseAbsoluteRow remains monotonic and the viewport resets via pinViewportToBottom() unless mAutoScrollDisabled is active (in which case it stays locked at the top of subsequent output, matching master).
  • Sub-pixel OverScroller rendering (TerminalView & TerminalRenderer):
    • Replace row-quantized Scroller with pixel-space OverScroller (mScrollPixels + mSubRowOffsetPixels in [0, mFontLineSpacing)), driving per-frame animation via computeScroll() and postInvalidateOnAnimation(), with boundary guards in onFling(), computeScroll(), and onDown() so boundary flings terminate immediately without swallowing subsequent single-tap gestures.
    • Roll back in-progress touch scroll state on MotionEvent.ACTION_CANCEL so gestures intercepted mid-drag by parent views (e.g. DrawerLayout) or system gestures restore the pre-gesture viewport state.
    • Add TerminalRenderer.render(..., float subRowOffsetPx, ...) (preserving the existing render(..., int topRow, ...) overload) that clips to the viewport and translates the canvas by -subRowOffsetPx, rendering one extra boundary row when subRowOffsetPx > 0.
    • Update getColumnAndRow(), getCursorY(), and getPointY() in TerminalView to account for mSubRowOffsetPixels.
  • Unit tests (ScrollPreservationTest):
    • Add unit tests covering monotonic document-row anchoring across live output, ring-buffer wraparound clamping, CSI 3 J / RIS transcript clear behavior (including long-session column-shrink redraws), and column-reflow resize preservation.

(Note for reviewers: This PR is independent of #5444, though both touch TerminalView / TerminalRenderer / TerminalEmulator. Happy to rebase whichever is reviewed second, or split the OverScroller rendering change from the scrollback behavior change if preferred.)

Testing

  • ./gradlew test (150 unit tests including ScrollPreservationTest) and ./gradlew assembleDebug in CI.
  • Backported onto v0.118.3 and tested on an Android device (touch drag/fling boundaries, live streaming output, split-screen, and floating window).

@qwerty123yucy
qwerty123yucy force-pushed the pr/anchored-overscroller branch from 369b6a7 to ddb6b5a Compare November 17, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant