native table border rendering

This commit is contained in:
jess 2026-04-04 22:44:23 -07:00
parent d1efbed9a8
commit 39feb208ab
1 changed files with 23 additions and 11 deletions

View File

@ -118,22 +118,34 @@ class MarkdownLayoutManager: NSLayoutManager {
charOffset += lineLen + 1
}
// Draw vertical column separators from first line pipe positions
// Draw vertical column separators using pipe character glyph positions
if let firstLine = lines.first {
let colWidth = rect.size.width / CGFloat(max(columns, 1))
for col in 1..<columns {
let x = rect.origin.x + colWidth * CGFloat(col)
let colLine = NSBezierPath()
colLine.move(to: NSPoint(x: x, y: rect.origin.y))
colLine.line(to: NSPoint(x: x, y: rect.origin.y + rect.size.height))
colLine.lineWidth = 0.5
Theme.current.surface2.setStroke()
colLine.stroke()
let nsFirstLine = firstLine as NSString
var pipeOffsets: [Int] = []
for i in 0..<nsFirstLine.length {
if nsFirstLine.character(at: i) == UInt16(UnicodeScalar("|").value) {
pipeOffsets.append(i)
}
}
// Skip first and last pipe (outer borders), draw inner separators
if pipeOffsets.count > 2 {
for pi in 1..<(pipeOffsets.count - 1) {
let charPos = charRange.location + pipeOffsets[pi]
let pipeGlyph = self.glyphRange(forCharacterRange: NSRange(location: charPos, length: 1), actualCharacterRange: nil)
let pipeRect = boundingRect(forGlyphRange: pipeGlyph, in: container)
let x = pipeRect.origin.x + origin.x + pipeRect.size.width / 2
let colLine = NSBezierPath()
colLine.move(to: NSPoint(x: x, y: rect.origin.y))
colLine.line(to: NSPoint(x: x, y: rect.origin.y + rect.size.height))
colLine.lineWidth = 0.5
Theme.current.surface2.setStroke()
colLine.stroke()
}
}
// Header background
if lines.count > 1 {
let firstLineRange = NSRange(location: charRange.location, length: (firstLine as NSString).length)
let firstLineRange = NSRange(location: charRange.location, length: nsFirstLine.length)
let headerGlyphRange = self.glyphRange(forCharacterRange: firstLineRange, actualCharacterRange: nil)
var headerRect = boundingRect(forGlyphRange: headerGlyphRange, in: container)
headerRect.origin.x = rect.origin.x