InstantPage V2: inset + round code blocks nested in blockquotes
A code block inside a blockquote was pinned to local x=0 / full width, so its background bled out under the quote bar instead of insetting to the quote's content gutter like the quote's text. Detect quote nesting via the raised child inset (threaded as LayoutContext.pageHorizontalInset) and, when nested, inset the background to honor horizontalInset and give it an 8pt rounded corner. Top-level and <details> code blocks stay flush, full-width, and square (matching V1) — the bubble's own rounded clip handles their edges. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9dada484aa
commit
a4cddb74d6
1 changed files with 12 additions and 4 deletions
|
|
@ -425,6 +425,7 @@ public func layoutInstantPageV2(
|
|||
rtl: instantPage.rtl,
|
||||
fitToWidth: fitToWidth,
|
||||
computeRevealCharacterRects: computeRevealCharacterRects,
|
||||
pageHorizontalInset: horizontalInset,
|
||||
mediaIndexCounter: 0,
|
||||
detailsIndexCounter: 0,
|
||||
expandedDetails: expandedDetails
|
||||
|
|
@ -540,6 +541,7 @@ private struct LayoutContext {
|
|||
let rtl: Bool
|
||||
let fitToWidth: Bool
|
||||
let computeRevealCharacterRects: Bool
|
||||
let pageHorizontalInset: CGFloat
|
||||
|
||||
var mediaIndexCounter: Int = 0
|
||||
var detailsIndexCounter: Int = 0
|
||||
|
|
@ -2192,7 +2194,6 @@ private func layoutCodeBlock(
|
|||
) -> [InstantPageV2LaidOutItem] {
|
||||
let backgroundInset: CGFloat = 15.0
|
||||
let textXOffset: CGFloat = 11.0
|
||||
let cornerRadius: CGFloat = 0.0
|
||||
|
||||
let attributedString: NSAttributedString
|
||||
if let language, !language.isEmpty {
|
||||
|
|
@ -2233,12 +2234,19 @@ private func layoutCodeBlock(
|
|||
height: textItem.frame.height
|
||||
)
|
||||
|
||||
// V1 line 348: block spans full boundingWidth (x=0), height = contentSize.height + backgroundInset*2.
|
||||
// Top-level (and <details>) code blocks span the full boundingWidth flush (x=0), matching V1
|
||||
// (line 348). Inside a blockquote the child inset is raised above the page inset (by
|
||||
// lineInset), so honor it here — otherwise the full-width background bleeds out under the
|
||||
// quote bar instead of insetting to the quote's content gutter like the quote's text does.
|
||||
let blockHeight = textSize.height + backgroundInset * 2.0
|
||||
let isNestedInQuote = horizontalInset > context.pageHorizontalInset
|
||||
// Inset (quote-nested) code blocks get an 8pt rounded background; flush (top-level / details)
|
||||
// ones stay square — the bubble's own rounded clip handles their edges.
|
||||
let cornerRadius: CGFloat = isNestedInQuote ? 8.0 : 0.0
|
||||
let blockFrame = CGRect(
|
||||
x: 0.0,
|
||||
x: isNestedInQuote ? horizontalInset : 0.0,
|
||||
y: 0.0,
|
||||
width: boundingWidth,
|
||||
width: isNestedInQuote ? (boundingWidth - horizontalInset * 2.0) : boundingWidth,
|
||||
height: blockHeight
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue