From 7ed7a56642dde05a5bb5b7d89fcfebe57bad4965 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Tue, 6 Oct 2026 12:04:37 +0200 Subject: [PATCH] fix(editor): translate decoration frames by textContainerOrigin (#71 follow-up 5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frames arrive in CONTAINER space; the view draws text at textContainerOrigin + frame. The missing +origin.y (inset height 20) drew every decoration 20pt too high — hairline ending above the quote, grid compressed over the table's top rows. Translate once, per-frame. --- Museion/ReadingSurface.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Museion/ReadingSurface.swift b/Museion/ReadingSurface.swift index 38de8db..7148c32 100644 --- a/Museion/ReadingSurface.swift +++ b/Museion/ReadingSurface.swift @@ -141,13 +141,18 @@ final class ReadingCanvasView: NSTextView { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) + let origin = textContainerOrigin for bound in blockBounds { guard let decoration = bound.decoration else { continue } + // frames arrive in CONTAINER space; the view draws text at + // textContainerOrigin + frame (inset shifts it — the missing + // +origin.y drew every decoration 20pt too high). let frames = framesForRange(bound.docRange) + .map { CGRect(x: $0.minX + origin.x, y: $0.minY + origin.y, width: $0.width, height: $0.height) } guard let firstFrame = frames.first, let lastFrame = frames.last else { continue } switch decoration { case let .quote(indent): - let x = textContainerOrigin.x + (textContainer?.lineFragmentPadding ?? 0) + indent - 6 + let x = (textContainer?.lineFragmentPadding ?? 0) + indent - 6 let path = NSBezierPath() path.move(to: NSPoint(x: x, y: firstFrame.minY)) path.line(to: NSPoint(x: x, y: lastFrame.maxY)) @@ -157,13 +162,13 @@ final class ReadingCanvasView: NSTextView { case .rule: let y = (firstFrame.minY + firstFrame.maxY) / 2 let path = NSBezierPath() - path.move(to: NSPoint(x: textContainerOrigin.x, y: y)) - path.line(to: NSPoint(x: textContainerOrigin.x + (textContainer?.size.width ?? 0), y: y)) + path.move(to: NSPoint(x: 0, y: y)) + path.line(to: NSPoint(x: (textContainer?.size.width ?? 0), y: y)) path.lineWidth = 1 ProseTypography.tableBorderColor.setStroke() path.stroke() case let .table(columns): - let originX = textContainerOrigin.x + (textContainer?.lineFragmentPadding ?? 0) + let originX = (textContainer?.lineFragmentPadding ?? 0) let path = NSBezierPath() for offset in columns { let x = originX + offset