fix: align note checkboxes with the text baseline
This commit is contained in:
@@ -1273,6 +1273,8 @@ func listCheckboxesStayCenteredInTheSharedColumnAtEachIndentation() throws {
|
||||
let editor = NotesTextView(frame: NSRect(x: 0, y: 0, width: 400, height: 300))
|
||||
let source = "- bullet\n- [ ] task\n12345. wide number\n + nested bullet\n - [x] nested task"
|
||||
editor.setMarkdownContents(NSAttributedString(string: source))
|
||||
MarkdownHighlighting.apply(to: editor)
|
||||
editor.refreshTasks()
|
||||
let layout = try #require(editor.layoutManager)
|
||||
let container = try #require(editor.textContainer)
|
||||
layout.ensureLayout(for: container)
|
||||
@@ -1288,6 +1290,11 @@ func listCheckboxesStayCenteredInTheSharedColumnAtEachIndentation() throws {
|
||||
.offsetBy(dx: editor.textContainerOrigin.x, dy: editor.textContainerOrigin.y)
|
||||
let checkbox = try #require(checkboxes.indices.contains(index) ? checkboxes[index] : nil)
|
||||
#expect(abs(checkbox.frame.midX - frame.midX) <= 0.5)
|
||||
let bodyGlyph = layout.glyphIndexForCharacter(at: body.location)
|
||||
let fragment = layout.lineFragmentRect(forGlyphAt: bodyGlyph, effectiveRange: nil)
|
||||
let baseline = editor.textContainerOrigin.y + fragment.minY + layout.location(forGlyphAt: bodyGlyph).y
|
||||
let font = try #require(editor.textStorage?.attribute(.font, at: body.location, effectiveRange: nil) as? NSFont)
|
||||
#expect(abs(checkbox.frame.midY - (baseline - font.capHeight / 2)) <= 0.5)
|
||||
}
|
||||
#expect(editor.markdownString == source)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user