Downgrade inline box break priority to emergency#550
Closed
devunt wants to merge 1 commit intolinebender:mainfrom
Closed
Downgrade inline box break priority to emergency#550devunt wants to merge 1 commit intolinebender:mainfrom
devunt wants to merge 1 commit intolinebender:mainfrom
Conversation
Change the line break opportunity marked after inline boxes from regular priority to emergency priority. This prevents inline boxes from being unconditionally separated onto their own line when followed by text using OverflowWrap::Anywhere or WordBreak::BreakAll. Previously, the regular-priority break after an inline box always won over emergency-priority character-level breaks (from BreakAll/Anywhere), regardless of proximity to the overflow point. This caused the inline box to be placed on its own line with the text starting on the next line — effectively losing the inline box's intended effect on the first line's layout (e.g., paragraph indentation via zero-height inline box). By marking the break as emergency priority instead, character-level breaks that are closer to the overflow point are now preferred. In scenarios without BreakAll/Anywhere, the behavior is preserved because emergency breaks serve as the same last-resort fallback.
Collaborator
|
Hmm... I can see the issue here. But I don't think this is the right fix. Seems to me that when I would add that creating a text indent is not an intended use case for inline boxes, and we really ought to implement a dedicated |
Author
|
I see. Let me discuss this further in #545. I'll close this for now. See you there! |
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
When an
InlineBoxis followed by text that usesOverflowWrap::AnywhereorWordBreak::BreakAll, the inline box is unconditionally separated onto its own line instead of remaining on the same line as the text. This PR fixes the issue by downgrading the break opportunity after inline boxes from regular to emergency priority.Problem
In
break_next(), after anInlineBoxis appended to the current line,mark_line_break_opportunity()is called unconditionally (line 258). This stores the position as a regular (prev_boundary) break opportunity.When the following text uses
BreakAll/Anywhere, character-level breaks are marked viamark_emergency_break_opportunity(), which stores them as emergency (emergency_boundary) breaks.When overflow occurs, parley's priority order is:
prev_boundary)emergency_boundary)Because regular always wins over emergency regardless of proximity to the overflow point, the inline box boundary is chosen over closer character-level breaks. This causes the inline box to be placed on its own line, and the text starts fresh on the next line — with full
max_advancewidth available, as if the inline box didn't exist.Concrete example
A common use case is paragraph indentation via a zero-height
InlineBox:Expected:
[InlineBox][aaaaaaa...]on the first line, text wraps between characters at overflow.Actual:
[InlineBox]alone on line 1 (invisible, zero-height),[aaaaaaa...]starts on line 2 with the full line width — the indent has no visible effect.Fix
Change
mark_line_break_opportunity()→mark_emergency_break_opportunity()after inline boxes (1-line change).This makes the inline box break the same priority as
BreakAll/Anywherecharacter breaks. Sinceemergency_boundarystores only the latest emergency break seen, character-level breaks closer to the overflow point naturally win.Behavior change analysis
Since
prev_boundaryandemergency_boundaryare bothOption<PrevBoundaryState>(storing only the latest position), the behavior difference depends on what other break opportunities exist:[InlineBox][continuous-text]+ BreakAll[InlineBox][continuous-text]+ normal mode[InlineBox][word1 word2 ...]overflow in later word[InlineBox][word1]where InlineBox+word1 overflowstext [InlineBox] longwordoverflow in longwordIn all non-
BreakAll/Anywherescenarios, behavior is effectively unchanged because:prev_boundaryafter theInlineBoxanyway, so theInlineBoxbreak was already irrelevant.InlineBoxbreak still works as an emergency fallback (emergency is used before accepting overflow).No API changes
InlineBoxstruct: unchanged