Skip to content

Commit 0acd458

Browse files
committed
Loosen RangeStoreElement Requirements
1 parent 1687258 commit 0acd458

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeContainer.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ class StyledRangeContainer {
8383
/// - Parameter range: The range to query.
8484
/// - Returns: An array of continuous styled runs.
8585
func runsIn(range: NSRange) -> [RangeStoreRun<StyleElement>] {
86+
func combineLowerPriority(_ lhs: inout RangeStoreRun<StyleElement>, _ rhs: RangeStoreRun<StyleElement>) {
87+
lhs.value = lhs.value?.combineLowerPriority(rhs.value) ?? rhs.value
88+
}
89+
90+
func combineHigherPriority(_ lhs: inout RangeStoreRun<StyleElement>, _ rhs: RangeStoreRun<StyleElement>) {
91+
lhs.value = lhs.value?.combineHigherPriority(rhs.value) ?? rhs.value
92+
}
93+
8694
// Ordered by priority, lower = higher priority.
8795
var allRuns = _storage.sorted(by: { $0.key < $1.key }).map { $0.value.runs(in: range.intRange) }
8896
var runs: [RangeStoreRun<StyleElement>] = []
@@ -97,9 +105,9 @@ class StyledRangeContainer {
97105
for idx in (0..<allRuns.count).reversed() where idx != minRunIdx {
98106
guard let last = allRuns[idx].last else { continue }
99107
if idx < minRunIdx {
100-
minRun.combineHigherPriority(last)
108+
combineHigherPriority(&minRun, last)
101109
} else {
102-
minRun.combineLowerPriority(last)
110+
combineLowerPriority(&minRun, last)
103111
}
104112

105113
if last.length == minRun.length {
@@ -120,7 +128,7 @@ class StyledRangeContainer {
120128
}
121129

122130
func storageUpdated(replacedContentIn range: Range<Int>, withCount newLength: Int) {
123-
for (key, value) in _storage {
131+
for key in _storage.keys {
124132
_storage[key]?.storageUpdated(replacedCharactersIn: range, withCount: newLength)
125133
}
126134
}

Sources/CodeEditSourceEditor/RangeStore/RangeStoreElement.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77

88
protocol RangeStoreElement: Equatable, Hashable {
99
var isEmpty: Bool { get }
10-
func combineLowerPriority(_ other: Self?) -> Self
11-
func combineHigherPriority(_ other: Self?) -> Self
1210
}

Sources/CodeEditSourceEditor/RangeStore/RangeStoreRun.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ struct RangeStoreRun<Element: RangeStoreElement>: Equatable, Hashable {
1818
value?.isEmpty ?? true
1919
}
2020

21-
mutating func combineLowerPriority(_ other: RangeStoreRun) {
22-
value = value?.combineLowerPriority(other.value) ?? other.value
23-
}
24-
25-
mutating func combineHigherPriority(_ other: RangeStoreRun) {
26-
value = value?.combineHigherPriority(other.value) ?? other.value
27-
}
28-
2921
mutating func subtractLength(_ other: borrowing RangeStoreRun) {
3022
self.length -= other.length
3123
}

0 commit comments

Comments
 (0)