forked from CodeEditApp/CodeEditTextView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextLayoutManager+Invalidation.swift
More file actions
42 lines (35 loc) · 1.3 KB
/
TextLayoutManager+Invalidation.swift
File metadata and controls
42 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// TextLayoutManager+Invalidation.swift
// CodeEditTextView
//
// Created by Khan Winter on 2/24/24.
//
import Foundation
extension TextLayoutManager {
/// Invalidates layout for the given rect.
/// - Parameter rect: The rect to invalidate.
public func invalidateLayoutForRect(_ rect: NSRect) {
for linePosition in lineStorage.linesStartingAt(rect.minY, until: rect.maxY) {
linePosition.data.setNeedsLayout()
}
layoutView?.needsLayout = true
}
/// Invalidates layout for the given range of text.
/// - Parameter range: The range of text to invalidate.
public func invalidateLayoutForRange(_ range: NSRange) {
for linePosition in lineStorage.linesInRange(range) {
linePosition.data.setNeedsLayout()
}
// Special case where we've deleted from the very end, `linesInRange` correctly does not return any lines
// So we need to invalidate the last line specifically.
if range.location == textStorage?.length, !lineStorage.isEmpty {
lineStorage.last?.data.setNeedsLayout()
}
layoutView?.needsLayout = true
}
public func setNeedsLayout() {
needsLayout = true
visibleLineIds.removeAll(keepingCapacity: true)
layoutView?.needsLayout = true
}
}