fix: align note checkboxes with the text baseline
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user