Skip to content

[chore:] Update CodeEditSourceEditor, add Find In Editor, Misc Bug Fixes #2020

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 3 commits into from
Apr 8, 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
18 changes: 9 additions & 9 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@
303E88462C276FD600EEA8D9 /* XCRemoteSwiftPackageReference "LanguageServerProtocol" */,
6C4E37FA2C73E00700AEE7B5 /* XCRemoteSwiftPackageReference "SwiftTerm" */,
6CB94D012CA1205100E8651C /* XCRemoteSwiftPackageReference "swift-async-algorithms" */,
30597BCA2D9AA5BE004BC2CC /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
6CFE18222DA59C9F00A7B796 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
);
preferredProjectObjectVersion = 55;
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
Expand Down Expand Up @@ -1649,14 +1649,6 @@
minimumVersion = 0.13.2;
};
};
30597BCA2D9AA5BE004BC2CC /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/CodeEditApp/CodeEditSourceEditor.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.10.0;
};
};
30CB648F2C16CA8100CC8A9E /* XCRemoteSwiftPackageReference "LanguageServerProtocol" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ChimeHQ/LanguageServerProtocol";
Expand Down Expand Up @@ -1753,6 +1745,14 @@
version = 1.0.1;
};
};
6CFE18222DA59C9F00A7B796 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/CodeEditApp/CodeEditSourceEditor";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.11.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "3d134b350244fc51aaff618575f0cb6d754dbbef6fb05b12964d922d42ce960e",
"originHash" : "ac57a6899925c3e4ac6d43aed791c845c6fc24a4441b6a10297a207d951b7836",
"pins" : [
{
"identity" : "anycodable",
Expand Down Expand Up @@ -33,8 +33,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditSourceEditor",
"state" : {
"revision" : "6b2c945501f0a5c15d8aa6d159fb2550c391bdd0",
"version" : "0.10.0"
"revision" : "f444927ab70015f4b76f119f6fc5d0e358fcd77a",
"version" : "0.11.0"
}
},
{
Expand All @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditTextView.git",
"state" : {
"revision" : "1792167c751b6668b4743600d2cf73d2829dd18a",
"version" : "0.7.9"
"revision" : "47faec9fb571c9c695897e69f0a4f08512ae682e",
"version" : "0.8.2"
}
},
{
Expand Down
40 changes: 13 additions & 27 deletions CodeEdit/Features/Editor/Views/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct CodeFileView: View {
var matchAppearance
@AppSettings(\.textEditing.letterSpacing)
var letterSpacing
@AppSettings(\.textEditing.bracketHighlight)
var bracketHighlight
@AppSettings(\.textEditing.bracketEmphasis)
var bracketEmphasis
@AppSettings(\.textEditing.useSystemCursor)
var useSystemCursor

Expand All @@ -50,6 +50,8 @@ struct CodeFileView: View {

@ObservedObject private var themeModel: ThemeModel = .shared

@State private var treeSitter = TreeSitterClient()

private var cancellables = Set<AnyCancellable>()

private let isEditable: Bool
Expand Down Expand Up @@ -99,23 +101,6 @@ struct CodeFileView: View {

@State private var font: NSFont = Settings[\.textEditing].font.current

@State private var bracketPairHighlight: BracketPairHighlight? = {
let theme = ThemeModel.shared.selectedTheme ?? ThemeModel.shared.themes.first!
let color = Settings[\.textEditing].bracketHighlight.useCustomColor
? Settings[\.textEditing].bracketHighlight.color.nsColor
: theme.editor.text.nsColor.withAlphaComponent(0.8)
switch Settings[\.textEditing].bracketHighlight.highlightType {
case .disabled:
return nil
case .flash:
return .flash
case .bordered:
return .bordered(color: color)
case .underline:
return .underline(color: color)
}
}()

@Environment(\.edgeInsets)
private var edgeInsets

Expand All @@ -132,10 +117,12 @@ struct CodeFileView: View {
editorOverscroll: overscroll.overscrollPercentage,
cursorPositions: $cursorPositions,
useThemeBackground: useThemeBackground,
highlightProviders: [treeSitter],
contentInsets: edgeInsets.nsEdgeInsets,
additionalTextInsets: NSEdgeInsets(top: 2, left: 0, bottom: 0, right: 0),
isEditable: isEditable,
letterSpacing: letterSpacing,
bracketPairHighlight: bracketPairHighlight,
bracketPairEmphasis: getBracketPairEmphasis(),
useSystemCursor: useSystemCursor,
undoManager: undoManager,
coordinators: textViewCoordinators
Expand All @@ -154,19 +141,18 @@ struct CodeFileView: View {
.onChange(of: settingsFont) { newFontSetting in
font = newFontSetting.current
}
.onChange(of: bracketHighlight) { _ in
bracketPairHighlight = getBracketPairHighlight()
}
}

private func getBracketPairHighlight() -> BracketPairHighlight? {
let color = if Settings[\.textEditing].bracketHighlight.useCustomColor {
Settings[\.textEditing].bracketHighlight.color.nsColor
/// Determines the style of bracket emphasis based on the `bracketEmphasis` setting and the current theme.
/// - Returns: The emphasis style to use for bracket pair emphasis.
private func getBracketPairEmphasis() -> BracketPairEmphasis? {
let color = if Settings[\.textEditing].bracketEmphasis.useCustomColor {
Settings[\.textEditing].bracketEmphasis.color.nsColor
} else {
currentTheme.editor.text.nsColor.withAlphaComponent(0.8)
}

switch Settings[\.textEditing].bracketHighlight.highlightType {
switch Settings[\.textEditing].bracketEmphasis.highlightType {
case .disabled:
return nil
case .flash:
Expand Down
4 changes: 2 additions & 2 deletions CodeEdit/Features/Editor/Views/EditorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ struct EditorAreaView: View {
}

var editorInsetAmount: Double {
let tabBarHeight = shouldShowTabBar ? (EditorTabBarView.height + 1) : 0
let jumpBarHeight = showEditorJumpBar ? (EditorJumpBarView.height + 1) : 0
let tabBarHeight = shouldShowTabBar ? (EditorTabBarView.height) : 0
let jumpBarHeight = showEditorJumpBar ? (EditorJumpBarView.height) : 0
return tabBarHeight + jumpBarHeight
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension SettingsData {
"Letter Spacing",
"Autocomplete braces",
"Enable type-over completion",
"Bracket Pair Emphasis",
"Bracket Pair Highlight"
]
if #available(macOS 14.0, *) {
Expand Down Expand Up @@ -64,7 +65,7 @@ extension SettingsData {
var letterSpacing: Double = 1.0

/// The behavior of bracket pair highlights.
var bracketHighlight: BracketPairHighlight = BracketPairHighlight()
var bracketEmphasis: BracketPairEmphasis = BracketPairEmphasis()

/// Use the system cursor for the source editor.
var useSystemCursor: Bool = true
Expand Down Expand Up @@ -107,10 +108,10 @@ extension SettingsData {
Double.self,
forKey: .letterSpacing
) ?? 1
self.bracketHighlight = try container.decodeIfPresent(
BracketPairHighlight.self,
forKey: .bracketHighlight
) ?? BracketPairHighlight()
self.bracketEmphasis = try container.decodeIfPresent(
BracketPairEmphasis.self,
forKey: .bracketEmphasis
) ?? BracketPairEmphasis()
if #available(macOS 14, *) {
self.useSystemCursor = try container.decodeIfPresent(Bool.self, forKey: .useSystemCursor) ?? true
} else {
Expand Down Expand Up @@ -164,7 +165,7 @@ extension SettingsData {
}
}

struct BracketPairHighlight: Codable, Hashable {
struct BracketPairEmphasis: Codable, Hashable {
/// The type of highlight to use
var highlightType: HighlightType = .flash
var useCustomColor: Bool = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,26 @@ private extension TextEditingSettingsView {
Group {
Picker(
"Bracket Pair Highlight",
selection: $textEditing.bracketHighlight.highlightType
selection: $textEditing.bracketEmphasis.highlightType
) {
Text("Disabled").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.disabled)
Text("Disabled").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.disabled)
Divider()
Text("Bordered").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.bordered)
Text("Flash").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.flash)
Text("Underline").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.underline)
Text("Bordered").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.bordered)
Text("Flash").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.flash)
Text("Underline").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.underline)
}
if [.bordered, .underline].contains(textEditing.bracketHighlight.highlightType) {
Toggle("Use Custom Color", isOn: $textEditing.bracketHighlight.useCustomColor)
if [.bordered, .underline].contains(textEditing.bracketEmphasis.highlightType) {
Toggle("Use Custom Color", isOn: $textEditing.bracketEmphasis.useCustomColor)
SettingsColorPicker(
"Bracket Pair Highlight Color",
color: $textEditing.bracketHighlight.color.swiftColor
color: $textEditing.bracketEmphasis.color.swiftColor
)
.foregroundColor(
textEditing.bracketHighlight.useCustomColor
textEditing.bracketEmphasis.useCustomColor
? Color(.labelColor)
: Color(.secondaryLabelColor)
)
.disabled(!textEditing.bracketHighlight.useCustomColor)
.disabled(!textEditing.bracketEmphasis.useCustomColor)
}
}
}
Expand Down