Skip to content

Commit 45ccd75

Browse files
committed
Back to where we started! (working)
1 parent 24d9b7a commit 45ccd75

15 files changed

Lines changed: 388 additions & 379 deletions

File tree

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

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

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ let package = Package(
1616
dependencies: [
1717
// A fast, efficient, text view for code.
1818
.package(
19-
url: "https://github.com/CodeEditApp/CodeEditTextView.git",
20-
from: "0.11.1"
19+
path: "../CodeEditTextView"
20+
// url: "https://github.com/CodeEditApp/CodeEditTextView.git",
21+
// from: "0.11.1"
2122
),
2223
// tree-sitter languages
2324
.package(

Sources/CodeEditSourceEditor/Highlighting/Highlighter.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,9 @@ extension Highlighter: NSTextStorageDelegate {
223223
) {
224224
// This method is called whenever attributes are updated, so to avoid re-highlighting the entire document
225225
// each time an attribute is applied, we check to make sure this is in response to an edit.
226-
guard editedMask.contains(.editedCharacters), let textView else { return }
227-
228-
let styleContainerRange: Range<Int>
229-
let newLength: Int
230-
231-
if editedRange.length == 0 { // Deleting, editedRange is at beginning of the range that was deleted
232-
styleContainerRange = editedRange.location..<(editedRange.location - delta)
233-
newLength = 0
234-
} else { // Replacing or inserting
235-
styleContainerRange = editedRange.location..<(editedRange.location + editedRange.length - delta)
236-
newLength = editedRange.length
237-
}
226+
guard editedMask.contains(.editedCharacters) else { return }
238227

239-
styleContainer.storageUpdated(
240-
replacedContentIn: styleContainerRange,
241-
withCount: newLength
242-
)
228+
styleContainer.storageUpdated(editedRange: editedRange, changeInLength: delta)
243229

244230
if delta > 0 {
245231
visibleRangeProvider.visibleSet.insert(range: editedRange)

Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeContainer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ class StyledRangeContainer {
127127
return runs.reversed()
128128
}
129129

130-
func storageUpdated(replacedContentIn range: Range<Int>, withCount newLength: Int) {
130+
func storageUpdated(editedRange: NSRange, changeInLength delta: Int) {
131131
for key in _storage.keys {
132-
_storage[key]?.storageUpdated(replacedCharactersIn: range, withCount: newLength)
132+
_storage[key]?.storageUpdated(editedRange: editedRange, changeInLength: delta)
133133
}
134134
}
135135
}

Sources/CodeEditSourceEditor/LineFolding/FoldProviders/IndentationLineFoldProvider.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,32 @@ final class IndentationLineFoldProvider: LineFoldProvider {
2222
func foldLevelAtLine(
2323
lineNumber: Int,
2424
lineRange: NSRange,
25-
currentDepth: Int,
25+
previousDepth: Int,
2626
text: NSTextStorage
27-
) -> LineFoldProviderLineInfo? {
27+
) -> [LineFoldProviderLineInfo] {
2828
guard let leadingIndent = text.leadingRange(in: lineRange, within: .whitespacesWithoutNewlines)?.length,
29-
leadingIndent > 0 else {
30-
return nil
29+
leadingIndent != lineRange.length else {
30+
return []
3131
}
3232

33-
if leadingIndent < currentDepth {
33+
var foldIndicators: [LineFoldProviderLineInfo] = []
34+
35+
if leadingIndent < previousDepth {
3436
// End the fold at the start of whitespace
35-
return .endFold(rangeEnd: lineRange.location + leadingIndent, newDepth: leadingIndent)
37+
foldIndicators.append(.endFold(rangeEnd: lineRange.location + leadingIndent, newDepth: leadingIndent))
3638
}
3739

3840
// Check if the next line has more indent
3941
let maxRange = NSRange(start: lineRange.max, end: text.length)
4042
guard let nextIndent = text.leadingRange(in: maxRange, within: .whitespacesWithoutNewlines)?.length,
4143
nextIndent > 0 else {
42-
return nil
44+
return foldIndicators
4345
}
4446

45-
if nextIndent > currentDepth, let trailingWhitespace = text.trailingWhitespaceRange(in: lineRange) {
46-
return .startFold(rangeStart: trailingWhitespace.location, newDepth: nextIndent)
47+
if nextIndent > leadingIndent, let trailingWhitespace = text.trailingWhitespaceRange(in: lineRange) {
48+
foldIndicators.append(.startFold(rangeStart: trailingWhitespace.location, newDepth: nextIndent))
4749
}
4850

49-
return nil
51+
return foldIndicators
5052
}
5153
}

Sources/CodeEditSourceEditor/LineFolding/FoldProviders/LineFoldProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protocol LineFoldProvider: AnyObject {
3535
func foldLevelAtLine(
3636
lineNumber: Int,
3737
lineRange: NSRange,
38-
currentDepth: Int,
38+
previousDepth: Int,
3939
text: NSTextStorage
40-
) -> LineFoldProviderLineInfo?
40+
) -> [LineFoldProviderLineInfo]
4141
}

Sources/CodeEditSourceEditor/LineFolding/Model/FoldRange.swift

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)