From 3edc8838d93fdda61e3f6d538d0b4fa8adf46569 Mon Sep 17 00:00:00 2001 From: jess Date: Tue, 7 Apr 2026 14:29:37 -0700 Subject: [PATCH] skip gutter line numbers for collapsed table/HR source ranges --- src/EditorView.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/EditorView.swift b/src/EditorView.swift index 4a37932..810e7b7 100644 --- a/src/EditorView.swift +++ b/src/EditorView.swift @@ -2745,6 +2745,19 @@ class LineNumberTextView: NSTextView { let lineMode = ConfigManager.shared.lineIndicatorMode + // Collect collapsed block source ranges (tables, HRs) to skip in gutter + var collapsedRanges: [NSRange] = [] + if let mlm = lm as? MarkdownLayoutManager { + for block in mlm.blockRanges { + switch block.kind { + case .tableBlock, .horizontalRule: + collapsedRanges.append(block.range) + default: + break + } + } + } + var containerVisible = visibleRect containerVisible.origin.x -= origin.x containerVisible.origin.y -= origin.y @@ -2784,6 +2797,14 @@ class LineNumberTextView: NSTextView { var charIndex = visibleChars.location while charIndex < NSMaxRange(visibleChars) { let lineRange = text.lineRange(for: NSRange(location: charIndex, length: 0)) + + let inCollapsedBlock = collapsedRanges.contains { NSIntersectionRange($0, lineRange).length > 0 } + if inCollapsedBlock { + lineNumber += 1 + charIndex = NSMaxRange(lineRange) + continue + } + let lineGlyphRange = lm.glyphRange(forCharacterRange: lineRange, actualCharacterRange: nil) let lineRect = lm.boundingRect(forGlyphRange: lineGlyphRange, in: tc) let y = lineRect.origin.y + origin.y