Fix iOS scroll locked to bottom during incoming data#468
Open
alvarolb wants to merge 1 commit intomigueldeicaza:mainfrom
Open
Fix iOS scroll locked to bottom during incoming data#468alvarolb wants to merge 1 commit intomigueldeicaza:mainfrom
alvarolb wants to merge 1 commit intomigueldeicaza:mainfrom
Conversation
Owner
|
I like the idea, but there are a few challenges with this patch
|
Owner
|
Oh, and I think that keyboard input needs to also auto-reset this. |
185c41e to
aa6a0f4
Compare
On iOS, updateScroller() unconditionally forced contentOffset to the bottom on every new line of output, preventing the user from scrolling up while the terminal was receiving data. Changes: 1. Derive contentOffset from yDisp — updateScroller() now uses the terminal's yDisp (already managed by Terminal.scroll) instead of always forcing to bottom. When userScrolling is true, yDisp stays stable so the view won't snap. 2. Track scroll via panGestureRecognizer — uses addTarget on the existing pan gesture instead of setting delegate = self, preserving delegate semantics for consumers of TerminalView. 3. Synchronize yDisp from contentOffset — after the user finishes scrolling (including deceleration), yDisp is updated to match the visual position, keeping buffer state in sync. 4. Detect deceleration end via CADisplayLink — uses the existing display link to check when deceleration ends, avoiding contentOffset didSet overrides that conflict with UIKit bounce animations. 5. Reset on buffer switch — bufferActivated() clears userScrolling so alternate screen transitions always snap to bottom. 6. Reset on keyboard input — commitTextInput() clears userScrolling and scrolls to bottom, since typing implies the user wants to see current output. 7. Conditional ensureCaretIsVisible — only scrolls to bottom if the caret is actually off-screen, matching macOS behavior.
aa6a0f4 to
0adae42
Compare
Owner
|
I got a GitHub notification for this, but when I click on it, it says nothing is there - would you mind posting your message again? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On iOS,
TerminalView(aUIScrollViewsubclass) always forcescontentOffsetto the bottom inupdateScroller(). This means the user cannot scroll up to read previous output while the terminal is actively receiving data — any new content immediately snaps the view back to the bottom.Approach
This follows the same pattern already used on macOS (where
updateScroller()only updates theNSScrollerwidget without forcing content position), adapted forUIScrollView:Derive contentOffset from yDisp —
updateScroller()now usesdisplayBuffer.yDisp(already managed byTerminal.scroll(isWrapped:)) instead of always forcing to the bottom. WhenuserScrollingis true,yDispstays stable so the view won't snap.Track scroll via panGestureRecognizer — Uses
addTargeton the existing pan gesture instead of settingdelegate = self, preserving delegate semantics for consumers ofTerminalView.Synchronize yDisp from contentOffset — After the user finishes scrolling (including deceleration),
yDispis updated to match the visual scroll position, keeping buffer state in sync.Detect deceleration end via CADisplayLink — Uses the existing display link to check when deceleration ends, avoiding
contentOffsetdidSetoverrides that conflict with UIKit bounce animations.Reset on buffer switch —
bufferActivated()clearsuserScrollingso alternate screen transitions always snap to bottom.Reset on keyboard input —
commitTextInput()clearsuserScrollingand scrolls to bottom, since typing implies the user wants to see current output.Conditional ensureCaretIsVisible — Only scrolls to bottom if the caret is actually off-screen, matching macOS behavior.
Changes
Sources/SwiftTerm/iOS/iOSTerminalView.swift: GuardcontentOffsetinupdateScroller(), add pan gesture tracking, syncyDispfrom scroll position, reset on buffer switch and keyboard input, conditionalensureCaretIsVisible.