diff --git a/src/EditorView.swift b/src/EditorView.swift index ca41746..59e7d41 100644 --- a/src/EditorView.swift +++ b/src/EditorView.swift @@ -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.. 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