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)