Skip to content

Commit d61866b

Browse files
Added editor overscroll setting
1 parent 13d98b7 commit d61866b

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ extension SettingsData {
1414
struct TextEditingSettings: Codable, Hashable, SearchableSettingsPage {
1515

1616
var searchKeys: [String] {
17-
[
17+
var keys = [
1818
"Prefer Indent Using",
1919
"Tab Width",
2020
"Wrap lines to editor width",
21+
"Overscroll",
2122
"Font",
2223
"Font Size",
2324
"Font Weight",
@@ -27,7 +28,10 @@ extension SettingsData {
2728
"Enable type-over completion",
2829
"Bracket Pair Highlight"
2930
]
30-
.map { NSLocalizedString($0, comment: "") }
31+
if #available(macOS 14.0, *) {
32+
keys.append("System Cursor")
33+
}
34+
return keys.map { NSLocalizedString($0, comment: "") }
3135
}
3236

3337
/// An integer indicating how many spaces a `tab` will appear as visually.
@@ -49,6 +53,9 @@ extension SettingsData {
4953
/// A flag indicating whether to wrap lines to editor width
5054
var wrapLinesToEditorWidth: Bool = true
5155

56+
/// The percentage of overscroll to apply to the text view
57+
var overscroll: OverscrollOption = .medium
58+
5259
/// A multiplier for setting the line height. Defaults to `1.2`
5360
var lineHeightMultiple: Double = 1.2
5461

@@ -88,6 +95,10 @@ extension SettingsData {
8895
Bool.self,
8996
forKey: .wrapLinesToEditorWidth
9097
) ?? true
98+
self.overscroll = try container.decodeIfPresent(
99+
OverscrollOption.self,
100+
forKey: .overscroll
101+
) ?? .medium
91102
self.lineHeightMultiple = try container.decodeIfPresent(
92103
Double.self,
93104
forKey: .lineHeightMultiple
@@ -167,6 +178,22 @@ extension SettingsData {
167178
case underline
168179
}
169180
}
181+
182+
enum OverscrollOption: String, Codable {
183+
case none
184+
case small
185+
case medium
186+
case large
187+
188+
var overscrollPercentage: CGFloat {
189+
switch self {
190+
case .none: return 0
191+
case .small: return 0.25
192+
case .medium: return 0.5
193+
case .large: return 0.75
194+
}
195+
}
196+
}
170197
}
171198

172199
struct EditorFont: Codable, Hashable {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct TextEditingSettingsView: View {
1919
defaultTabWidth
2020
wrapLinesToEditorWidth
2121
useSystemCursor
22+
overscroll
2223
}
2324
Section {
2425
fontSelector
@@ -80,6 +81,31 @@ private extension TextEditingSettingsView {
8081
}
8182
}
8283

84+
@ViewBuilder private var overscroll: some View {
85+
Group {
86+
Picker(
87+
"Editor Overscroll",
88+
selection: $textEditing.overscroll
89+
) {
90+
Text("None")
91+
.tag(SettingsData.TextEditingSettings.OverscrollOption.none)
92+
Divider()
93+
Text("Small")
94+
.tag(
95+
SettingsData.TextEditingSettings.OverscrollOption.small
96+
)
97+
Text("Medium")
98+
.tag(
99+
SettingsData.TextEditingSettings.OverscrollOption.medium
100+
)
101+
Text("Large")
102+
.tag(
103+
SettingsData.TextEditingSettings.OverscrollOption.large
104+
)
105+
}
106+
}
107+
}
108+
83109
@ViewBuilder private var lineHeight: some View {
84110
Stepper(
85111
"Line Height",

0 commit comments

Comments
 (0)