fix: draw native list attachment markers
This commit is contained in:
@@ -824,3 +824,35 @@ func mixedListMarkersAlignBodyGlyphsAndWrappedLinesWithoutChangingMarkdown() thr
|
||||
#expect(editor.markdownContents.attribute(markerAttribute, at: 0, effectiveRange: nil) as? String == "first")
|
||||
#expect(editor.markdownContents.attribute(markerAttribute, at: 2, effectiveRange: nil) as? String == "third")
|
||||
}
|
||||
|
||||
@Test @MainActor
|
||||
func renderedListMarkersPaintBulletsAndNumbersInsideTheirGlyphFrames() throws {
|
||||
_ = NSApplication.shared
|
||||
let editor = NotesTextView(frame: NSRect(x: 0, y: 0, width: 400, height: 200))
|
||||
editor.isRichText = true
|
||||
for source in ["- item", "* item", "+ item", "1. item", "123) item"] {
|
||||
editor.setMarkdownContents(NSAttributedString(string: source))
|
||||
let layout = try #require(editor.layoutManager)
|
||||
let container = try #require(editor.textContainer)
|
||||
layout.ensureLayout(for: container)
|
||||
let glyphs = layout.glyphRange(forCharacterRange: NSRange(location: 0, length: 1), actualCharacterRange: nil)
|
||||
let frame = layout.boundingRect(forGlyphRange: glyphs, in: container)
|
||||
let bitmap = try #require(NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: 160, pixelsHigh: 48,
|
||||
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false,
|
||||
colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0))
|
||||
let context = try #require(NSGraphicsContext(bitmapImageRep: bitmap))
|
||||
NSGraphicsContext.saveGraphicsState()
|
||||
NSGraphicsContext.current = context
|
||||
context.cgContext.clear(CGRect(x: 0, y: 0, width: 160, height: 48))
|
||||
layout.drawGlyphs(forGlyphRange: glyphs, at: NSPoint(x: 4 - frame.minX, y: 10 - frame.minY))
|
||||
NSGraphicsContext.restoreGraphicsState()
|
||||
var painted = false
|
||||
for y in 0..<48 {
|
||||
for x in 0..<160 where (bitmap.colorAt(x: x, y: y)?.alphaComponent ?? 0) > 0.1 {
|
||||
painted = true
|
||||
}
|
||||
}
|
||||
#expect(painted, "The actual TextKit draw path must paint the marker for \(source)")
|
||||
#expect(editor.markdownString == source)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user