fix: align note checkboxes with the text baseline

This commit is contained in:
2026-10-19 21:05:18 +02:00
parent 9e92dc3d7f
commit fe252cb648
3 changed files with 14 additions and 3 deletions
+6 -2
View File
@@ -611,15 +611,19 @@ final class NotesTextView: NSTextView, @MainActor NSLayoutManagerDelegate {
}
private func positionCheckboxes() {
guard !checkboxes.isEmpty, let layoutManager, let textContainer else { return }
guard !checkboxes.isEmpty, let layoutManager, let textContainer, let textStorage else { return }
layoutManager.ensureLayout(for: textContainer)
for checkbox in checkboxes {
let task = tasks[checkbox.tag]
let glyphs = layoutManager.glyphRange(forCharacterRange: task.range, actualCharacterRange: nil)
let rect = layoutManager.boundingRect(forGlyphRange: glyphs, in: textContainer)
.offsetBy(dx: textContainerOrigin.x, dy: textContainerOrigin.y)
let bodyGlyph = layoutManager.glyphIndexForCharacter(at: min(NSMaxRange(task.range) + 1, textStorage.length - 1))
let fragment = layoutManager.lineFragmentRect(forGlyphAt: bodyGlyph, effectiveRange: nil)
let baseline = textContainerOrigin.y + fragment.minY + layoutManager.location(forGlyphAt: bodyGlyph).y
let centerY = baseline - NotesAppearance.font.capHeight / 2
checkbox.setFrameOrigin(NSPoint(x: rect.midX - checkbox.frame.width / 2,
y: rect.midY - checkbox.frame.height / 2))
y: centerY - checkbox.frame.height / 2))
}
}