Skip to content

Update CodeEditTextView to 0.12.0 #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct ContentView: View {
indentOption: $indentOption,
reformatAtColumn: $reformatAtColumn,
showReformattingGuide: $showReformattingGuide,
showFoldingRibbon: $showFoldingRibbon
showFoldingRibbon: $showFoldingRibbon,
invisibles: $invisibleCharactersConfig,
warningCharacters: $warningCharacters
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ struct StatusBar: View {
.foregroundStyle(.secondary)

Button {
state.findPanelVisible.toggle()
state.findPanelVisible?.toggle()
} label: {
Text(state.findPanelVisible ? "Hide" : "Show") + Text(" Find")
Text(state.findPanelVisible ?? false ? "Hide" : "Show") + Text(" Find")
}
.buttonStyle(.borderless)
.foregroundStyle(.secondary)
Expand Down Expand Up @@ -198,7 +198,9 @@ struct StatusBar: View {
/// Create a label string for cursor positions.
/// - Parameter cursorPositions: The cursor positions to create the label for.
/// - Returns: A string describing the user's location in a document.
func getLabel(_ cursorPositions: [CursorPosition]) -> String {
func getLabel(_ cursorPositions: [CursorPosition]?) -> String {
guard let cursorPositions else { return "No cursor" }

if cursorPositions.isEmpty {
return "No cursor"
}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
// A fast, efficient, text view for code.
.package(
url: "https://github.com/CodeEditApp/CodeEditTextView.git",
from: "0.11.4"
from: "0.12.0"
),
// tree-sitter languages
.package(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

extension NSEdgeInsets: Equatable {
extension NSEdgeInsets: @retroactive Equatable {
public static func == (lhs: NSEdgeInsets, rhs: NSEdgeInsets) -> Bool {
lhs.bottom == rhs.bottom &&
lhs.top == rhs.top &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import CodeEditTextView
import TextStory
import TextFormation

extension TextView: TextInterface {
extension TextView: @retroactive TextStoring {}
extension TextView: @retroactive TextInterface {
public var selectedRange: NSRange {
get {
return selectionManager
Expand Down Expand Up @@ -45,6 +46,6 @@ extension TextView: TextInterface {
in: mutation.range,
replacementLength: (mutation.string as NSString).length
)
layoutManager.setNeedsLayout()
layoutManager.invalidateLayoutForRange(mutation.range)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Highlighter: NSObject {

// MARK: NSTextStorageDelegate

extension Highlighter: NSTextStorageDelegate {
extension Highlighter: @preconcurrency NSTextStorageDelegate {
/// Processes an edited range in the text.
func textStorage(
_ textStorage: NSTextStorage,
Expand Down
35 changes: 25 additions & 10 deletions Sources/CodeEditSourceEditor/Minimap/MinimapLineFragmentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,40 @@ final class MinimapLineFragmentView: LineFragmentView {

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

// Create the drawing runs using attribute information
var position = newFragment.documentRange.location
var position = fragmentRange.location

for contentRun in newFragment.contents {
switch contentRun.data {
case .text:
addDrawingRunsUntil(max: position + contentRun.length, position: &position, textStorage: textStorage)
addDrawingRunsUntil(
max: position + contentRun.length,
position: &position,
textStorage: textStorage,
fragmentRange: fragmentRange
)
case .attachment(let attachment):
position += attachment.range.length
appendDrawingRun(color: .clear, range: NSRange(location: position, length: contentRun.length))
appendDrawingRun(
color: .clear,
range: NSRange(location: position, length: contentRun.length),
fragmentRange: fragmentRange
)
}
}
}

private func addDrawingRunsUntil(max: Int, position: inout Int, textStorage: NSTextStorage) {
private func addDrawingRunsUntil(
max: Int,
position: inout Int,
textStorage: NSTextStorage,
fragmentRange: NSRange
) {
while position < max {
var longestRange: NSRange = .notFound
defer { position = longestRange.max }
Expand All @@ -83,7 +98,7 @@ final class MinimapLineFragmentView: LineFragmentView {
if let scalar = UnicodeScalar(char), CharacterSet.whitespacesAndNewlines.contains(scalar) {
// Whitespace
if range != .notFound {
appendDrawingRun(color: foregroundColor, range: range)
appendDrawingRun(color: foregroundColor, range: range, fragmentRange: fragmentRange)
range = .notFound
}
} else {
Expand All @@ -97,7 +112,7 @@ final class MinimapLineFragmentView: LineFragmentView {
}

if range != .notFound {
appendDrawingRun(color: foregroundColor, range: range)
appendDrawingRun(color: foregroundColor, range: range, fragmentRange: fragmentRange)
}
}
}
Expand All @@ -106,12 +121,12 @@ final class MinimapLineFragmentView: LineFragmentView {
/// - Parameters:
/// - color: The color of the run, will have opacity applied by this method.
/// - range: The range, relative to the document. Will be normalized to the fragment by this method.
private func appendDrawingRun(color: NSColor, range: NSRange) {
private func appendDrawingRun(color: NSColor, range: NSRange, fragmentRange: NSRange) {
drawingRuns.append(
Run(
color: color.withAlphaComponent(0.4),
range: NSRange(
location: range.location - (lineFragment?.documentRange.location ?? 0),
location: range.location - fragmentRange.location,
length: range.length
)
)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CodeEditSourceEditorTests/RangeStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct RangeStoreTests {
func initWithLength() {
for _ in 0..<100 {
let length = Int.random(in: 0..<1000)
var store = Store(documentLength: length)
let store = Store(documentLength: length)
#expect(store.length == length)
}
}
Expand Down