diff --git a/Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeContainer.swift b/Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeContainer.swift index 95c81cb7e..f0677416b 100644 --- a/Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeContainer.swift +++ b/Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeContainer.swift @@ -45,6 +45,31 @@ class StyledRangeContainer { } } + enum RunState { + case empty + case value(RangeStoreRun) + case exhausted + + var isExhausted: Bool { + if case .exhausted = self { return true } + return false + } + + var hasValue: Bool { + if case .value = self { return true } + return false + } + + var length: Int { + switch self { + case .empty, .exhausted: + return 0 + case .value(let run): + return run.length + } + } + } + var _storage: [ProviderID: RangeStore] = [:] weak var delegate: StyledRangeContainerDelegate? @@ -118,7 +143,9 @@ class StyledRangeContainer { } } - allRuns[minRunIdx].removeLast() + if !allRuns[minRunIdx].isEmpty { + allRuns[minRunIdx].removeLast() + } runs.append(minRun) minValue = allRuns.compactMap { $0.last }.enumerated().min(by: { $0.1.length < $1.1.length }) diff --git a/Sources/CodeEditSourceEditor/SourceEditor/SourceEditor.swift b/Sources/CodeEditSourceEditor/SourceEditor/SourceEditor.swift index 3b2496aa1..efd1fcd8d 100644 --- a/Sources/CodeEditSourceEditor/SourceEditor/SourceEditor.swift +++ b/Sources/CodeEditSourceEditor/SourceEditor/SourceEditor.swift @@ -149,7 +149,8 @@ public struct SourceEditor: NSViewControllerRepresentable { controller.setCursorPositions(cursorPositions) } - if let scrollPosition = state.scrollPosition, scrollPosition != state.scrollPosition { + let scrollView = controller.scrollView + if let scrollPosition = state.scrollPosition, scrollPosition != scrollView?.contentView.bounds.origin { controller.scrollView.scroll(controller.scrollView.contentView, to: scrollPosition) controller.scrollView.reflectScrolledClipView(controller.scrollView.contentView) controller.gutterView.needsDisplay = true