Skip to content

Commit e9136b4

Browse files
Update CodeEditTextView to 0.12.0 (#347)
Updates CodeEditTextView to `0.12.0`
1 parent fe51d30 commit e9136b4

File tree

9 files changed

+47
-20
lines changed

9 files changed

+47
-20
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct ContentView: View {
8888
indentOption: $indentOption,
8989
reformatAtColumn: $reformatAtColumn,
9090
showReformattingGuide: $showReformattingGuide,
91-
showFoldingRibbon: $showFoldingRibbon
91+
showFoldingRibbon: $showFoldingRibbon,
9292
invisibles: $invisibleCharactersConfig,
9393
warningCharacters: $warningCharacters
9494
)

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/StatusBar.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ struct StatusBar: View {
118118
.foregroundStyle(.secondary)
119119

120120
Button {
121-
state.findPanelVisible.toggle()
121+
state.findPanelVisible?.toggle()
122122
} label: {
123-
Text(state.findPanelVisible ? "Hide" : "Show") + Text(" Find")
123+
Text(state.findPanelVisible ?? false ? "Hide" : "Show") + Text(" Find")
124124
}
125125
.buttonStyle(.borderless)
126126
.foregroundStyle(.secondary)
@@ -198,7 +198,9 @@ struct StatusBar: View {
198198
/// Create a label string for cursor positions.
199199
/// - Parameter cursorPositions: The cursor positions to create the label for.
200200
/// - Returns: A string describing the user's location in a document.
201-
func getLabel(_ cursorPositions: [CursorPosition]) -> String {
201+
func getLabel(_ cursorPositions: [CursorPosition]?) -> String {
202+
guard let cursorPositions else { return "No cursor" }
203+
202204
if cursorPositions.isEmpty {
203205
return "No cursor"
204206
}

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
// A fast, efficient, text view for code.
1818
.package(
1919
url: "https://github.com/CodeEditApp/CodeEditTextView.git",
20-
from: "0.11.4"
20+
from: "0.12.0"
2121
),
2222
// tree-sitter languages
2323
.package(

Sources/CodeEditSourceEditor/Extensions/NSEdgeInsets/NSEdgeInsets+Equatable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
extension NSEdgeInsets: Equatable {
10+
extension NSEdgeInsets: @retroactive Equatable {
1111
public static func == (lhs: NSEdgeInsets, rhs: NSEdgeInsets) -> Bool {
1212
lhs.bottom == rhs.bottom &&
1313
lhs.top == rhs.top &&

Sources/CodeEditSourceEditor/Extensions/TextView+/TextView+TextFormation.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import CodeEditTextView
1010
import TextStory
1111
import TextFormation
1212

13-
extension TextView: TextInterface {
13+
extension TextView: @retroactive TextStoring {}
14+
extension TextView: @retroactive TextInterface {
1415
public var selectedRange: NSRange {
1516
get {
1617
return selectionManager
@@ -45,6 +46,6 @@ extension TextView: TextInterface {
4546
in: mutation.range,
4647
replacementLength: (mutation.string as NSString).length
4748
)
48-
layoutManager.setNeedsLayout()
49+
layoutManager.invalidateLayoutForRange(mutation.range)
4950
}
5051
}

Sources/CodeEditSourceEditor/Highlighting/Highlighter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class Highlighter: NSObject {
214214

215215
// MARK: NSTextStorageDelegate
216216

217-
extension Highlighter: NSTextStorageDelegate {
217+
extension Highlighter: @preconcurrency NSTextStorageDelegate {
218218
/// Processes an edited range in the text.
219219
func textStorage(
220220
_ textStorage: NSTextStorage,

Sources/CodeEditSourceEditor/Minimap/MinimapLineFragmentView.swift

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,40 @@ final class MinimapLineFragmentView: LineFragmentView {
4343

4444
/// Set the new line fragment, and calculate drawing runs for drawing the fragment in the view.
4545
/// - Parameter newFragment: The new fragment to use.
46-
override func setLineFragment(_ newFragment: LineFragment, renderer: LineFragmentRenderer) {
47-
super.setLineFragment(newFragment, renderer: renderer)
46+
override func setLineFragment(_ newFragment: LineFragment, fragmentRange: NSRange, renderer: LineFragmentRenderer) {
47+
super.setLineFragment(newFragment, fragmentRange: fragmentRange, renderer: renderer)
4848
guard let textStorage else { return }
49+
let fragmentRange = newFragment.documentRange
4950

5051
// Create the drawing runs using attribute information
51-
var position = newFragment.documentRange.location
52+
var position = fragmentRange.location
5253

5354
for contentRun in newFragment.contents {
5455
switch contentRun.data {
5556
case .text:
56-
addDrawingRunsUntil(max: position + contentRun.length, position: &position, textStorage: textStorage)
57+
addDrawingRunsUntil(
58+
max: position + contentRun.length,
59+
position: &position,
60+
textStorage: textStorage,
61+
fragmentRange: fragmentRange
62+
)
5763
case .attachment(let attachment):
5864
position += attachment.range.length
59-
appendDrawingRun(color: .clear, range: NSRange(location: position, length: contentRun.length))
65+
appendDrawingRun(
66+
color: .clear,
67+
range: NSRange(location: position, length: contentRun.length),
68+
fragmentRange: fragmentRange
69+
)
6070
}
6171
}
6272
}
6373

64-
private func addDrawingRunsUntil(max: Int, position: inout Int, textStorage: NSTextStorage) {
74+
private func addDrawingRunsUntil(
75+
max: Int,
76+
position: inout Int,
77+
textStorage: NSTextStorage,
78+
fragmentRange: NSRange
79+
) {
6580
while position < max {
6681
var longestRange: NSRange = .notFound
6782
defer { position = longestRange.max }
@@ -83,7 +98,7 @@ final class MinimapLineFragmentView: LineFragmentView {
8398
if let scalar = UnicodeScalar(char), CharacterSet.whitespacesAndNewlines.contains(scalar) {
8499
// Whitespace
85100
if range != .notFound {
86-
appendDrawingRun(color: foregroundColor, range: range)
101+
appendDrawingRun(color: foregroundColor, range: range, fragmentRange: fragmentRange)
87102
range = .notFound
88103
}
89104
} else {
@@ -97,7 +112,7 @@ final class MinimapLineFragmentView: LineFragmentView {
97112
}
98113

99114
if range != .notFound {
100-
appendDrawingRun(color: foregroundColor, range: range)
115+
appendDrawingRun(color: foregroundColor, range: range, fragmentRange: fragmentRange)
101116
}
102117
}
103118
}
@@ -106,12 +121,12 @@ final class MinimapLineFragmentView: LineFragmentView {
106121
/// - Parameters:
107122
/// - color: The color of the run, will have opacity applied by this method.
108123
/// - range: The range, relative to the document. Will be normalized to the fragment by this method.
109-
private func appendDrawingRun(color: NSColor, range: NSRange) {
124+
private func appendDrawingRun(color: NSColor, range: NSRange, fragmentRange: NSRange) {
110125
drawingRuns.append(
111126
Run(
112127
color: color.withAlphaComponent(0.4),
113128
range: NSRange(
114-
location: range.location - (lineFragment?.documentRange.location ?? 0),
129+
location: range.location - fragmentRange.location,
115130
length: range.length
116131
)
117132
)

Tests/CodeEditSourceEditorTests/RangeStoreTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct RangeStoreTests {
1414
func initWithLength() {
1515
for _ in 0..<100 {
1616
let length = Int.random(in: 0..<1000)
17-
var store = Store(documentLength: length)
17+
let store = Store(documentLength: length)
1818
#expect(store.length == length)
1919
}
2020
}

0 commit comments

Comments
 (0)