fix(editor): translate decoration frames by textContainerOrigin (#71 follow-up 5)

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.
This commit is contained in:
AlexKucera committed 2026-10-06 12:04:37 +02:00
1 parent d9cb615bc2
commit 7ed7a56642
1 file changed
+9 -4
+9 -4
View File
@@ -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