Skip to content

Commit f919bbb

Browse files
[chore:] Update CodeEditSourceEditor, add Find In Editor, Misc Bug Fixes (#2020)
### Description Updates CodeEditSourceEditor. Includes: - Find in Editor feature. - Improved undo grouping. - Improved word detection when selecting words. - Improved overscroll behavior. - Added mouse drag selection modes. ### Related Issues * CodeEditApp/CodeEditTextView#1 * CodeEditApp/CodeEditSourceEditor#295 ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code
1 parent 050c3e3 commit f919bbb

File tree

6 files changed

+46
-59
lines changed

6 files changed

+46
-59
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@
419419
303E88462C276FD600EEA8D9 /* XCRemoteSwiftPackageReference "LanguageServerProtocol" */,
420420
6C4E37FA2C73E00700AEE7B5 /* XCRemoteSwiftPackageReference "SwiftTerm" */,
421421
6CB94D012CA1205100E8651C /* XCRemoteSwiftPackageReference "swift-async-algorithms" */,
422-
30597BCA2D9AA5BE004BC2CC /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
422+
6CFE18222DA59C9F00A7B796 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
423423
);
424424
preferredProjectObjectVersion = 55;
425425
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
@@ -1649,14 +1649,6 @@
16491649
minimumVersion = 0.13.2;
16501650
};
16511651
};
1652-
30597BCA2D9AA5BE004BC2CC /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
1653-
isa = XCRemoteSwiftPackageReference;
1654-
repositoryURL = "https://github.com/CodeEditApp/CodeEditSourceEditor.git";
1655-
requirement = {
1656-
kind = upToNextMajorVersion;
1657-
minimumVersion = 0.10.0;
1658-
};
1659-
};
16601652
30CB648F2C16CA8100CC8A9E /* XCRemoteSwiftPackageReference "LanguageServerProtocol" */ = {
16611653
isa = XCRemoteSwiftPackageReference;
16621654
repositoryURL = "https://github.com/ChimeHQ/LanguageServerProtocol";
@@ -1753,6 +1745,14 @@
17531745
version = 1.0.1;
17541746
};
17551747
};
1748+
6CFE18222DA59C9F00A7B796 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
1749+
isa = XCRemoteSwiftPackageReference;
1750+
repositoryURL = "https://github.com/CodeEditApp/CodeEditSourceEditor";
1751+
requirement = {
1752+
kind = upToNextMajorVersion;
1753+
minimumVersion = 0.11.0;
1754+
};
1755+
};
17561756
/* End XCRemoteSwiftPackageReference section */
17571757

17581758
/* Begin XCSwiftPackageProductDependency section */

CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

CodeEdit/Features/Editor/Views/CodeFileView.swift

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct CodeFileView: View {
4040
var matchAppearance
4141
@AppSettings(\.textEditing.letterSpacing)
4242
var letterSpacing
43-
@AppSettings(\.textEditing.bracketHighlight)
44-
var bracketHighlight
43+
@AppSettings(\.textEditing.bracketEmphasis)
44+
var bracketEmphasis
4545
@AppSettings(\.textEditing.useSystemCursor)
4646
var useSystemCursor
4747

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

5151
@ObservedObject private var themeModel: ThemeModel = .shared
5252

53+
@State private var treeSitter = TreeSitterClient()
54+
5355
private var cancellables = Set<AnyCancellable>()
5456

5557
private let isEditable: Bool
@@ -99,23 +101,6 @@ struct CodeFileView: View {
99101

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

102-
@State private var bracketPairHighlight: BracketPairHighlight? = {
103-
let theme = ThemeModel.shared.selectedTheme ?? ThemeModel.shared.themes.first!
104-
let color = Settings[\.textEditing].bracketHighlight.useCustomColor
105-
? Settings[\.textEditing].bracketHighlight.color.nsColor
106-
: theme.editor.text.nsColor.withAlphaComponent(0.8)
107-
switch Settings[\.textEditing].bracketHighlight.highlightType {
108-
case .disabled:
109-
return nil
110-
case .flash:
111-
return .flash
112-
case .bordered:
113-
return .bordered(color: color)
114-
case .underline:
115-
return .underline(color: color)
116-
}
117-
}()
118-
119104
@Environment(\.edgeInsets)
120105
private var edgeInsets
121106

@@ -132,10 +117,12 @@ struct CodeFileView: View {
132117
editorOverscroll: overscroll.overscrollPercentage,
133118
cursorPositions: $cursorPositions,
134119
useThemeBackground: useThemeBackground,
120+
highlightProviders: [treeSitter],
135121
contentInsets: edgeInsets.nsEdgeInsets,
122+
additionalTextInsets: NSEdgeInsets(top: 2, left: 0, bottom: 0, right: 0),
136123
isEditable: isEditable,
137124
letterSpacing: letterSpacing,
138-
bracketPairHighlight: bracketPairHighlight,
125+
bracketPairEmphasis: getBracketPairEmphasis(),
139126
useSystemCursor: useSystemCursor,
140127
undoManager: undoManager,
141128
coordinators: textViewCoordinators
@@ -154,19 +141,18 @@ struct CodeFileView: View {
154141
.onChange(of: settingsFont) { newFontSetting in
155142
font = newFontSetting.current
156143
}
157-
.onChange(of: bracketHighlight) { _ in
158-
bracketPairHighlight = getBracketPairHighlight()
159-
}
160144
}
161145

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

169-
switch Settings[\.textEditing].bracketHighlight.highlightType {
155+
switch Settings[\.textEditing].bracketEmphasis.highlightType {
170156
case .disabled:
171157
return nil
172158
case .flash:

CodeEdit/Features/Editor/Views/EditorAreaView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ struct EditorAreaView: View {
4646
}
4747

4848
var editorInsetAmount: Double {
49-
let tabBarHeight = shouldShowTabBar ? (EditorTabBarView.height + 1) : 0
50-
let jumpBarHeight = showEditorJumpBar ? (EditorJumpBarView.height + 1) : 0
49+
let tabBarHeight = shouldShowTabBar ? (EditorTabBarView.height) : 0
50+
let jumpBarHeight = showEditorJumpBar ? (EditorJumpBarView.height) : 0
5151
return tabBarHeight + jumpBarHeight
5252
}
5353

CodeEdit/Features/Settings/Pages/TextEditingSettings/Models/TextEditingSettings.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extension SettingsData {
2626
"Letter Spacing",
2727
"Autocomplete braces",
2828
"Enable type-over completion",
29+
"Bracket Pair Emphasis",
2930
"Bracket Pair Highlight"
3031
]
3132
if #available(macOS 14.0, *) {
@@ -64,7 +65,7 @@ extension SettingsData {
6465
var letterSpacing: Double = 1.0
6566

6667
/// The behavior of bracket pair highlights.
67-
var bracketHighlight: BracketPairHighlight = BracketPairHighlight()
68+
var bracketEmphasis: BracketPairEmphasis = BracketPairEmphasis()
6869

6970
/// Use the system cursor for the source editor.
7071
var useSystemCursor: Bool = true
@@ -107,10 +108,10 @@ extension SettingsData {
107108
Double.self,
108109
forKey: .letterSpacing
109110
) ?? 1
110-
self.bracketHighlight = try container.decodeIfPresent(
111-
BracketPairHighlight.self,
112-
forKey: .bracketHighlight
113-
) ?? BracketPairHighlight()
111+
self.bracketEmphasis = try container.decodeIfPresent(
112+
BracketPairEmphasis.self,
113+
forKey: .bracketEmphasis
114+
) ?? BracketPairEmphasis()
114115
if #available(macOS 14, *) {
115116
self.useSystemCursor = try container.decodeIfPresent(Bool.self, forKey: .useSystemCursor) ?? true
116117
} else {
@@ -164,7 +165,7 @@ extension SettingsData {
164165
}
165166
}
166167

167-
struct BracketPairHighlight: Codable, Hashable {
168+
struct BracketPairEmphasis: Codable, Hashable {
168169
/// The type of highlight to use
169170
var highlightType: HighlightType = .flash
170171
var useCustomColor: Bool = false

CodeEdit/Features/Settings/Pages/TextEditingSettings/TextEditingSettingsView.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,26 +176,26 @@ private extension TextEditingSettingsView {
176176
Group {
177177
Picker(
178178
"Bracket Pair Highlight",
179-
selection: $textEditing.bracketHighlight.highlightType
179+
selection: $textEditing.bracketEmphasis.highlightType
180180
) {
181-
Text("Disabled").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.disabled)
181+
Text("Disabled").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.disabled)
182182
Divider()
183-
Text("Bordered").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.bordered)
184-
Text("Flash").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.flash)
185-
Text("Underline").tag(SettingsData.TextEditingSettings.BracketPairHighlight.HighlightType.underline)
183+
Text("Bordered").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.bordered)
184+
Text("Flash").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.flash)
185+
Text("Underline").tag(SettingsData.TextEditingSettings.BracketPairEmphasis.HighlightType.underline)
186186
}
187-
if [.bordered, .underline].contains(textEditing.bracketHighlight.highlightType) {
188-
Toggle("Use Custom Color", isOn: $textEditing.bracketHighlight.useCustomColor)
187+
if [.bordered, .underline].contains(textEditing.bracketEmphasis.highlightType) {
188+
Toggle("Use Custom Color", isOn: $textEditing.bracketEmphasis.useCustomColor)
189189
SettingsColorPicker(
190190
"Bracket Pair Highlight Color",
191-
color: $textEditing.bracketHighlight.color.swiftColor
191+
color: $textEditing.bracketEmphasis.color.swiftColor
192192
)
193193
.foregroundColor(
194-
textEditing.bracketHighlight.useCustomColor
194+
textEditing.bracketEmphasis.useCustomColor
195195
? Color(.labelColor)
196196
: Color(.secondaryLabelColor)
197197
)
198-
.disabled(!textEditing.bracketHighlight.useCustomColor)
198+
.disabled(!textEditing.bracketEmphasis.useCustomColor)
199199
}
200200
}
201201
}

0 commit comments

Comments
 (0)