From 3c3a5865bd9ad89f40422ce6c35f5dfc618827b1 Mon Sep 17 00:00:00 2001 From: psmattas Date: Thu, 20 Aug 2026 13:49:43 +0100 Subject: [PATCH] fix: seed code-block cache on programmatic document load updateCodeBlockSelection was only ever called from the two AppKit text-delegate callbacks (textDidChange / selection-changed), never from the programmatic rebuildTextStorageAndStyle load path. Line number gutters (and the built-in copy-code button) stayed empty on a cold document open until the user's first click or keystroke. Threads the rebuild's own parsed document into the same call instead of leaving cachedCodeBlockTokens empty until the next real edit. --- .../Coordinator/NativeTextViewCoordinator+Restyling.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Vendor/swift-markdown-engine/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Restyling.swift b/Vendor/swift-markdown-engine/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Restyling.swift index 7133867..4b3c152 100644 --- a/Vendor/swift-markdown-engine/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Restyling.swift +++ b/Vendor/swift-markdown-engine/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Restyling.swift @@ -185,6 +185,13 @@ extension NativeTextViewCoordinator { previousActiveTokenIndices = activeTokenIndices previousCaretLocation = finalSelection.location previousSelectedRange = finalSelection + + // FIX: seed cachedCodeBlockTokens on the programmatic load path too — + // it was previously only populated by the AppKit text-delegate + // callbacks (textDidChange / selection-changed), so code-block + // overlays (line-number gutters, the built-in copy button) stayed + // empty on a cold document open until the user's first keystroke. + updateCodeBlockSelection(textView: textView, parsed: parsed) } // Reconcile wide-table overlays after layout settles.