Repository navigation
Scroll code blocks and wide display formulas sideways - #37
Merged
Merged
Conversation
TranscriptStyle gets three options. All defaults keep the current behavior. - codeWraps: when it is false, a line of code breaks only at a line break in its text. - displayMathAlignment: puts a paragraph that holds only display math at the leading edge, the center or the trailing edge. - displayMathScrolls: when it is true, a display formula that is wider than the column keeps its size instead of a scale-down. BlockLayout records the right edge of its widest line and how far its lines can move left. A streamed block keeps that value for the lines that it does not typeset again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SideScroll keeps an offset for each block that scrolls sideways, by block id. A block that grows keeps its id, so it keeps its offset. Each use cuts the offset to what the block can scroll. DocumentLayout draws the lines of such a block moved left by its offset and clips them to the box of the block. The code background, list markers and quote bars do not move. Caret rects, closest offsets, links and selection rects use the same offset. A caret or a selection rect outside the box moves to the edge of the box. The public methods use no offset, so the text past the edge stays out of reach. The tail and the text that fades in are drawn with the offset that the view gives the layout engine. Each output records that offset, so the view can find a tail that it drew before the latest scroll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the style lets blocks scroll, TranscriptTextView adds a pan gesture recognizer. The pan starts only when all of these are true: - The touch is in the box of a block whose lines are wider than the box. - The drag goes more sideways than up or down. - The block can still move in that direction. - The touch is not on a selection handle. The scroll views around the view wait for this pan to fail. Thus a sideways drag in the block moves only the block, and a vertical drag still scrolls the host. After the pan, the block slows down at the normal deceleration rate of a scroll view. A touch on the block stops it. Each step draws the band of the block in the tiles again. If the tail showed the block, the tiles take that part back. Caret rects, selection rects, closest positions and link taps use the offsets. A view that is not selectable still takes touches in a block that scrolls. A new document clears the offsets. A document that grows keeps them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At the debug level, the view logs the offset and the maximum offset of the block when a pan ends and when the block stops after it. The log category is SideScroll. It is shown in the Xcode console, and in Console when debug messages are on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With -wideSample, the intro and the streamed answer end with a code block that has a long line and a wide display formula. With -sideScroll, the demo sets codeWraps to false, displayMathScrolls to true and displayMathAlignment to leading. Without -sideScroll, the same text shows the default behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A line of code that does not wrap breaks only at a line break, however long it is. - The tail renderer draws a block again when its offset changed. A pan hides an old tail and does not wait for the layout queue. Only the blocks in the tail count when the view compares offsets. - No text fades in while a block that text streams into moves sideways. Fading text that reaches into a block that moves shows at rest. - A block keeps its offset while the new document has a block with that id and the same kind. A new document clears all offsets. - The sideways pan gets only the touches in blocks that scroll, so other drags do not wait for it. It checks the point where the touch went down. A touch that stops a moving block opens no link. - Tag shapes and tag images in a block that scrolls are not cut. A tag animation in such a block does not play. - Only the glyphs near the box are drawn for a line wider than the box. - A pan that ends too slowly to go on logs "Stopped". - With VoiceOver, a three-finger swipe scrolls the block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DocumentLayout.draw: the function takes highContrast before hiding, and scroll last. DocumentLayout.draw, drawLine: the glyphs get both the visible range and highContrast. DocumentLayout.draw: the image loop stays in the scrolled box, and its images get the quote text color. DocumentLayout.drawGlyphs: the function takes both visible and highContrast, and keeps the doc of visible. FadeRenderer.render: the function takes scroll, and a change of highContrast draws the pieces again. TailRenderer: the draw call gives both highContrast and scroll. TranscriptTextView: the draw call gives both highContrast and the side scroll. TranscriptTextView.style: the setter calls styleChanged() and then updateSidePan(). README: the display math options come before the formula cache text. README: the LaTeX of a scrolled formula shows when there is no renderer or the renderer returns nil. SideScrollTests: the draw calls give highContrast: false. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Part 7 of a stack of 13 pull requests. The base is #36 (
feature/bold-text-contrast). #31 (part 1) tells how to merge the stack.On this stacked branch,
swift testpasses (287 tests), and the iOS build and build-for-testing pass.Summary
Model output often has code lines and display formulas that are wider than the screen. Before this change, code wrapped, and wide formulas scaled down to fit. To keep the lines whole, an app had to put the text view in a horizontal scroll view, which then drew every tile of the block. Now a block can scroll sideways inside
TranscriptTextView. The block keeps the width of the column, and only its text moves. All new options default to the current behavior. Tables do not change.TranscriptStyle.codeWraps(defaulttrue). When it isfalse, a line of code breaks only at a line break, and a wide block scrolls sideways.TranscriptStyle.displayMathScrolls(defaultfalse). When it istrue, a wide display formula keeps its size and scrolls sideways, and its LaTeX shows whole, not cut with "…". Inline formulas still scale down to fit.TranscriptStyle.displayMathAlignment(default.center): the leading edge, the center or the trailing edge. A formula wider than the column starts at the leading edge.DocumentLayoutuse no offset.TranscriptTextView. It takes only touches in a block that can scroll, and only sideways drags in a direction that the block can move. Scroll views around the view wait for it to fail. After the pan, the block slows down as a scroll view does. A touch stops it and opens no link.SideScrollcategory, debug level).-wideSampleand-sideScrolllaunch arguments to the demo app, and document the options in the README.Tests
swift teston macOS: 206 tests pass. 27 new tests inSideScrollTests.swiftcover lines that do not wrap, streamed blocks, display math, offset limits, carets, hit tests, selection, links, drawing pixel by pixel, the tail, fades, kept offsets, the pan decision and the slow-down.Checked on an iPhone 12 mini
iOS 27.0, in a check screen in a local test app. The check ran on main first. Main showed each problem, except in the first item, which looks for a change and finds none.
false. The branch moves 274 pt for each step.Stand-ins: drags and flings are touches that the check app injects, through hit testing and the gesture recognizers. The VoiceOver swipe is a call to
accessibilityScroll(_:). The films are snapshots of the view on each frame, not a screen recording.Not checked
Known limits
🤖 Generated with Claude Code