From 5912f0fdffb9e5dd5998ca6c0a4ba35d2a24c29a Mon Sep 17 00:00:00 2001 From: Gary Tokman Date: Mon, 2 Nov 2026 17:07:00 -0500 Subject: [PATCH] Expose the first visible diff cell for presentation anchors --- .../DiffFilesView/DiffFilesViewController.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/MarkdownView/Components/DiffFilesView/DiffFilesViewController.swift b/Sources/MarkdownView/Components/DiffFilesView/DiffFilesViewController.swift index 9c840f3..af81534 100644 --- a/Sources/MarkdownView/Components/DiffFilesView/DiffFilesViewController.swift +++ b/Sources/MarkdownView/Components/DiffFilesView/DiffFilesViewController.swift @@ -175,6 +175,17 @@ import Foundation document.files.map(\.displayPath) } + public var firstVisibleDiffCell: UICollectionViewCell? { + guard isViewLoaded else { return nil } + collectionView.layoutIfNeeded() + for indexPath in collectionView.indexPathsForVisibleItems.sorted() { + if case .hunk? = dataSource.itemIdentifier(for: indexPath) { + return collectionView.cellForItem(at: indexPath) + } + } + return nil + } + override public func viewDidLoad() { super.viewDidLoad() view.backgroundColor = DiffFilesViewConfiguration.backgroundColor(theme: theme)