fix(text): reset continued state when an explicit position is given (#1641)#1748
Open
JamBalaya56562 wants to merge 1 commit into
Open
Conversation
…oliojs#1641) A `text` call that passes an explicit x or y coordinate and is not itself `continued` now discards any wrapping state left behind by a previous `continued: true` run, so the coordinate is honored as absolute instead of being offset by the previous run's inline position. Rich-text sequences (whose continuing segments pass no coordinates) are unaffected. Adds regression tests and documents the forward-looking nature of the `continued` flag. Co-Authored-By: Claude Opus 4.8 <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.
Summary
Fixes #1641.
When a
text()call passes an explicitx/ycoordinate and is not itselfcontinued, it now discards any wrapping state left behind by a previouscontinued: truerun and draws at the absolute coordinate you pass — instead of being offset by the previous run's inline position.The problem
continuedis a forward-looking flag: the state is saved based on the current call's flag and reused by the next call (lib/mixins/text.js#L91-L92), and the next_textreusesthis._wrapperunconditionally at L84. On continuation the savedcontinuedXis added to the currentxin the wrapper'sfirstLinehandler (line_wrapper.js#L48-L49, accumulated at L352). So a coordinate passed to the call immediately after a continued run is offset, not absolute:FRESH484.02(= 400 + accumulated inline width)400Previously the only way to avoid this was to set
continued: falseon the last segment of the run, which is awkward inside loops and when delegating text to helper functions.The fix
A guard at the top of
_text: if a positionalxoryis given and the call isn't itselfcontinued, clearthis._wrapper/this._textOptionsbefore initializing options.continuedXlives on the wrapper instance, so dropping the wrapper resets it to0naturally.Why this is safe (not a breaking change)
The canonical rich-text idiom continues to work unchanged, because continuing segments pass no coordinates:
Verified against the rest of the codebase:
continuedunit/visual tests and thedocs/text.mdexamples pass no coordinates on the continuing call → unaffected.heightOfStringalready nulls this state today → behavior identical.boundsOfStringuses a local wrapper and never touchesthis._wrapper→ unaffected.listuses its own wrapper via_initOptions→ unaffected.tablerenders each cell at explicit coordinates and cells don't continue → unaffected (and now protected from state bleeding into a cell).Tests & docs
tests/unit/text.spec.js: explicit position resets after a continued run; a continued run without coordinates still flows inline.docs/text.mdthatcontinuedis forward-looking, how to end a run, and that an explicit position starts a call fresh.Full
tests/unit+tests/visualsuites pass (the onepdfmake/tablesfailure is a pre-existing default-5s-timeout flake that also fails onmasterand passes with a longer timeout — unrelated to this change).🤖 Generated with Claude Code