Skip to content

Commit

Permalink
Mutate view hierarchy only on annotations count change
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Dec 27, 2023
1 parent 9e66e48 commit 89555f8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/AnnotationsPlugin/AnnotationsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ extension AnnotationsPlugin {
guard let dataSource = parent.dataSource else {
return
}

let annotations = dataSource.textViewAnnotations()
guard annotations.count != annotationsViews.count else {
return
}

// Remove all views
for view in annotationsViews {
Expand All @@ -92,7 +97,7 @@ extension AnnotationsPlugin {

// Add views for annotations
let textLayoutManager = context.textView.textLayoutManager
for annotation in dataSource.textViewAnnotations() {
for annotation in annotations {
textLayoutManager.ensureLayout(for: NSTextRange(location: annotation.location))
if let textLineFragment = textLayoutManager.textLineFragment(at: annotation.location) {
if let annotationView = dataSource.textView(context.textView, viewForLineAnnotation: annotation, textLineFragment: textLineFragment) {
Expand Down

0 comments on commit 89555f8

Please sign in to comment.