Skip to content

Commit 4f4de36

Browse files
committed
Correctly Call Layout
1 parent 2fdbed0 commit 4f4de36

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Sources/CodeEditSourceEditor/Minimap/MinimapView+Draw.swift renamed to Sources/CodeEditSourceEditor/Minimap/MinimapContentView.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// MinimapView+Draw.swift
2+
// MinimapContentView.swift
33
// CodeEditSourceEditor
44
//
55
// Created by Khan Winter on 4/16/25.
@@ -8,8 +8,13 @@
88
import AppKit
99
import CodeEditTextView
1010

11+
/// Displays the real contents of the minimap. The layout manager and selection manager place views and draw into this
12+
/// view.
13+
///
14+
/// Height and position are managed by ``MinimapView``.
1115
public class MinimapContentView: FlippedNSView {
1216
weak var textView: TextView?
17+
weak var layoutManager: TextLayoutManager?
1318
weak var selectionManager: TextSelectionManager?
1419

1520
override public func draw(_ dirtyRect: NSRect) {
@@ -18,4 +23,9 @@ public class MinimapContentView: FlippedNSView {
1823
selectionManager?.drawSelections(in: dirtyRect)
1924
}
2025
}
26+
27+
override public func layout() {
28+
super.layout()
29+
layoutManager?.layoutLines()
30+
}
2131
}

Sources/CodeEditSourceEditor/Minimap/MinimapView+DocumentVisibleView.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ extension MinimapView {
5858
if minimapHeight > containerHeight {
5959
setScrollViewPosition(scrollPercentage: scrollPercentage)
6060
}
61-
62-
layoutManager.layoutLines()
6361
}
6462

6563
private func setScrollViewPosition(scrollPercentage: CGFloat) {

Sources/CodeEditSourceEditor/Minimap/MinimapView.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public class MinimapView: FlippedNSView {
137137
renderDelegate: lineRenderer
138138
)
139139
self.layoutManager = layoutManager
140+
self.contentView.layoutManager = layoutManager
140141
(textView.textStorage.delegate as? MultiStorageDelegate)?.addDelegate(layoutManager)
141142
}
142143

@@ -244,7 +245,6 @@ public class MinimapView: FlippedNSView {
244245
}
245246

246247
override public func layout() {
247-
layoutManager?.layoutLines()
248248
super.layout()
249249
updateContentViewHeight()
250250
updateDocumentVisibleViewPosition()
@@ -279,9 +279,15 @@ public class MinimapView: FlippedNSView {
279279
let overscroll = containerHeight * overscrollAmount * (estimatedContentHeight / editorEstimatedHeight)
280280
let height = estimatedContentHeight + overscroll
281281

282+
// This seems odd, but this reduces layout passes drastically
283+
let newFrame = CGRect(
284+
origin: contentView.frame.origin,
285+
size: CGSize(width: contentView.frame.width, height: height)
286+
).pixelAligned
287+
282288
// Only update a frame if needed
283-
if contentView.frame.height != height && height.isFinite && height < (textView?.frame.height ?? 0.0) {
284-
contentView.frame.size.height = height
289+
if contentView.frame != newFrame && height.isFinite && height < (textView?.frame.height ?? 0.0) {
290+
contentView.frame = newFrame
285291
}
286292
}
287293

0 commit comments

Comments
 (0)