Skip to content

Commit 92f1216

Browse files
Merge branch 'main' into itembox
2 parents d1a4604 + 603e89c commit 92f1216

File tree

23 files changed

+525
-221
lines changed

23 files changed

+525
-221
lines changed

.github/scripts/tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export LC_CTYPE=en_US.UTF-8
1616
set -o pipefail && arch -"${ARCH}" xcodebuild \
1717
-scheme CodeEditSourceEditor \
1818
-derivedDataPath ".build" \
19-
-destination "platform=macos,arch=${ARCH}" \
19+
-destination "platform=macOS,arch=${ARCH},name=My Mac" \
2020
-skipPackagePluginValidation \
2121
clean test | xcpretty

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

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

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/xcshareddata/xcschemes/CodeEditSourceEditorExample.xcscheme

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
3030
shouldUseLaunchSchemeArgsEnv = "YES"
3131
shouldAutocreateTestPlan = "YES">
32+
<Testables>
33+
<TestableReference
34+
skipped = "NO">
35+
<BuildableReference
36+
BuildableIdentifier = "primary"
37+
BlueprintIdentifier = "CodeEditSourceEditorTests"
38+
BuildableName = "CodeEditSourceEditorTests"
39+
BlueprintName = "CodeEditSourceEditorTests"
40+
ReferencedContainer = "container:../..">
41+
</BuildableReference>
42+
</TestableReference>
43+
</Testables>
3244
</TestAction>
3345
<LaunchAction
3446
buildConfiguration = "Debug"

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/EditorTheme+Default.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ import CodeEditSourceEditor
1212
extension EditorTheme {
1313
static var standard: EditorTheme {
1414
EditorTheme(
15-
text: .init(hex: "000000"),
16-
insertionPoint: .init(hex: "000000"),
17-
invisibles: .init(hex: "D6D6D6"),
18-
background: .init(hex: "FFFFFF"),
19-
lineHighlight: .init(hex: "ECF5FF"),
20-
selection: .init(hex: "B2D7FF"),
21-
keywords: .init(hex: "9B2393"),
22-
commands: .init(hex: "326D74"),
23-
types: .init(hex: "0B4F79"),
24-
attributes: .init(hex: "815F03"),
25-
variables: .init(hex: "0F68A0"),
26-
values: .init(hex: "6C36A9"),
27-
numbers: .init(hex: "1C00CF"),
28-
strings: .init(hex: "C41A16"),
29-
characters: .init(hex: "1C00CF"),
30-
comments: .init(hex: "267507")
15+
text: Attribute(color: NSColor(hex: "000000")),
16+
insertionPoint: NSColor(hex: "000000"),
17+
invisibles: Attribute(color: NSColor(hex: "D6D6D6")),
18+
background: NSColor(hex: "FFFFFF"),
19+
lineHighlight: NSColor(hex: "ECF5FF"),
20+
selection: NSColor(hex: "B2D7FF"),
21+
keywords: Attribute(color: NSColor(hex: "9B2393"), bold: true),
22+
commands: Attribute(color: NSColor(hex: "326D74")),
23+
types: Attribute(color: NSColor(hex: "0B4F79")),
24+
attributes: Attribute(color: NSColor(hex: "815F03")),
25+
variables: Attribute(color: NSColor(hex: "0F68A0")),
26+
values: Attribute(color: NSColor(hex: "6C36A9")),
27+
numbers: Attribute(color: NSColor(hex: "1C00CF")),
28+
strings: Attribute(color: NSColor(hex: "C41A16"), bold: true, italic: true),
29+
characters: Attribute(color: NSColor(hex: "1C00CF")),
30+
comments: Attribute(color: NSColor(hex: "267507"), italic: true)
3131
)
3232
}
3333
}

Package.resolved

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

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.7.7"
20+
from: "0.8.1"
2121
),
2222
// tree-sitter languages
2323
.package(

Sources/CodeEditSourceEditor/CodeEditSourceEditor/CodeEditSourceEditor.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
5757
editorOverscroll: CGFloat = 0,
5858
cursorPositions: Binding<[CursorPosition]>,
5959
useThemeBackground: Bool = true,
60-
highlightProviders: [HighlightProviding] = [TreeSitterClient()],
60+
highlightProviders: [any HighlightProviding] = [TreeSitterClient()],
6161
contentInsets: NSEdgeInsets? = nil,
6262
isEditable: Bool = true,
6363
isSelectable: Bool = true,
@@ -132,7 +132,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
132132
editorOverscroll: CGFloat = 0,
133133
cursorPositions: Binding<[CursorPosition]>,
134134
useThemeBackground: Bool = true,
135-
highlightProviders: [HighlightProviding] = [TreeSitterClient()],
135+
highlightProviders: [any HighlightProviding] = [TreeSitterClient()],
136136
contentInsets: NSEdgeInsets? = nil,
137137
isEditable: Bool = true,
138138
isSelectable: Bool = true,
@@ -179,7 +179,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
179179
private var editorOverscroll: CGFloat
180180
package var cursorPositions: Binding<[CursorPosition]>
181181
private var useThemeBackground: Bool
182-
private var highlightProviders: [HighlightProviding]
182+
private var highlightProviders: [any HighlightProviding]
183183
private var contentInsets: NSEdgeInsets?
184184
private var isEditable: Bool
185185
private var isSelectable: Bool
@@ -305,6 +305,10 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
305305
controller.useSystemCursor = useSystemCursor
306306
}
307307

308+
if !areHighlightProvidersEqual(controller: controller) {
309+
controller.setHighlightProviders(highlightProviders)
310+
}
311+
308312
controller.bracketPairHighlight = bracketPairHighlight
309313
}
310314

@@ -326,7 +330,12 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
326330
controller.tabWidth == tabWidth &&
327331
controller.letterSpacing == letterSpacing &&
328332
controller.bracketPairHighlight == bracketPairHighlight &&
329-
controller.useSystemCursor == useSystemCursor
333+
controller.useSystemCursor == useSystemCursor &&
334+
areHighlightProvidersEqual(controller: controller)
335+
}
336+
337+
private func areHighlightProvidersEqual(controller: TextViewController) -> Bool {
338+
controller.highlightProviders.map { ObjectIdentifier($0) } == highlightProviders.map { ObjectIdentifier($0) }
330339
}
331340
}
332341

Sources/CodeEditSourceEditor/Controller/TextViewController+Highlighter.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import SwiftTreeSitter
1010

1111
extension TextViewController {
12-
internal func setUpHighlighter() {
12+
package func setUpHighlighter() {
1313
if let highlighter {
1414
textView.removeStorageDelegate(highlighter)
1515
self.highlighter = nil
@@ -24,12 +24,23 @@ extension TextViewController {
2424
textView.addStorageDelegate(highlighter)
2525
self.highlighter = highlighter
2626
}
27+
28+
/// Sets new highlight providers. Recognizes when objects move in the array or are removed or inserted.
29+
///
30+
/// This is in place of a setter on the ``highlightProviders`` variable to avoid wasting resources setting up
31+
/// providers early.
32+
///
33+
/// - Parameter newProviders: All the new providers.
34+
package func setHighlightProviders(_ newProviders: [HighlightProviding]) {
35+
highlighter?.setProviders(newProviders)
36+
highlightProviders = newProviders
37+
}
2738
}
2839

2940
extension TextViewController: ThemeAttributesProviding {
3041
public func attributesFor(_ capture: CaptureName?) -> [NSAttributedString.Key: Any] {
3142
[
32-
.font: font,
43+
.font: theme.fontFor(for: capture, from: font),
3344
.foregroundColor: theme.colorFor(capture),
3445
.kern: textView.kern
3546
]

Sources/CodeEditSourceEditor/Controller/TextViewController+IndentLines.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//
22
// TextViewController+IndentLines.swift
3-
//
3+
// CodeEditTextView
44
//
55
// Created by Ludwig, Tom on 11.09.24.
66
//
77

8-
import CodeEditTextView
98
import AppKit
9+
import CodeEditTextView
1010

1111
extension TextViewController {
1212
/// Handles indentation and unindentation

Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import AppKit
9+
import CodeEditTextView
910

1011
extension TextViewController {
1112
package func generateParagraphStyle() -> NSMutableParagraphStyle {
@@ -66,6 +67,6 @@ extension TextViewController {
6667
} else {
6768
scrollView.automaticallyAdjustsContentInsets = true
6869
}
69-
scrollView.contentInsets.bottom = (contentInsets?.bottom ?? 0) + bottomContentInsets
70+
scrollView.contentInsets.bottom = contentInsets?.bottom ?? 0
7071
}
7172
}

0 commit comments

Comments
 (0)