Skip to content

Commit 68abe9e

Browse files
committed
Add Editor Options Accessory, Minimap Setting
1 parent 3d64ff1 commit 68abe9e

File tree

6 files changed

+84
-36
lines changed

6 files changed

+84
-36
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 8 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-
6CFE18222DA59C9F00A7B796 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
422+
6C7638E22DB1665800BA6353 /* XCLocalSwiftPackageReference "../CodeEditSourceEditor" */,
423423
);
424424
preferredProjectObjectVersion = 55;
425425
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
@@ -1616,6 +1616,13 @@
16161616
};
16171617
/* End XCConfigurationList section */
16181618

1619+
/* Begin XCLocalSwiftPackageReference section */
1620+
6C7638E22DB1665800BA6353 /* XCLocalSwiftPackageReference "../CodeEditSourceEditor" */ = {
1621+
isa = XCLocalSwiftPackageReference;
1622+
relativePath = ../CodeEditSourceEditor;
1623+
};
1624+
/* End XCLocalSwiftPackageReference section */
1625+
16191626
/* Begin XCRemoteSwiftPackageReference section */
16201627
2816F592280CF50500DD548B /* XCRemoteSwiftPackageReference "CodeEditSymbols" */ = {
16211628
isa = XCRemoteSwiftPackageReference;
@@ -1745,14 +1752,6 @@
17451752
version = 1.0.1;
17461753
};
17471754
};
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-
};
17561755
/* End XCRemoteSwiftPackageReference section */
17571756

17581757
/* Begin XCSwiftPackageProductDependency section */

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

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

CodeEdit/Features/Editor/TabBar/Views/EditorTabBarTrailingAccessories.swift

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
import SwiftUI
99

1010
struct EditorTabBarTrailingAccessories: View {
11+
@AppSettings(\.textEditing.wrapLinesToEditorWidth)
12+
var wrapLinesToEditorWidth
13+
@AppSettings(\.textEditing.showMinimap)
14+
var showMinimap
15+
1116
@Environment(\.splitEditor)
1217
var splitEditor
1318

@@ -21,15 +26,56 @@ struct EditorTabBarTrailingAccessories: View {
2126

2227
@EnvironmentObject private var editor: Editor
2328

29+
/// Because this view isn't invalidated with the `editor.selectedTab?.file.fileDocument` changes, this allows us
30+
/// to refresh relevant views when settings change.
31+
@State private var refreshToggleBool: Bool = false
32+
2433
var body: some View {
25-
HStack(spacing: 0) {
34+
HStack(spacing: 6) {
35+
// Once more options are implemented that are available for non-code documents, remove this if statement
36+
if let codeFile = editor.selectedTab?.file.fileDocument {
37+
editorOptionsMenu(codeFile: codeFile)
38+
Divider()
39+
.padding(.vertical, 10)
40+
}
2641
splitviewButton
2742
}
43+
.buttonStyle(.icon)
44+
.disabled(editorManager.isFocusingActiveEditor)
45+
.opacity(editorManager.isFocusingActiveEditor ? 0.5 : 1)
2846
.padding(.horizontal, 7)
2947
.opacity(activeState != .inactive ? 1.0 : 0.5)
3048
.frame(maxHeight: .infinity) // Fill out vertical spaces.
3149
}
3250

51+
func editorOptionsMenu(codeFile: CodeFileDocument) -> some View {
52+
// This is a button so it gets the same styling from the Group in `body`.
53+
Button(action: {}, label: { Image(systemName: "slider.horizontal.3") })
54+
.overlay {
55+
Menu {
56+
Toggle("Show Minimap", isOn: $showMinimap)
57+
.keyboardShortcut("M", modifiers: [.command, .shift, .control])
58+
Divider()
59+
Toggle(
60+
"Wrap Lines",
61+
isOn: Binding(
62+
get: { codeFile.wrapLines ?? wrapLinesToEditorWidth },
63+
set: {
64+
codeFile.wrapLines = $0
65+
refreshToggleBool.toggle()
66+
}
67+
)
68+
)
69+
.tag(refreshToggleBool)
70+
} label: {}
71+
.menuStyle(.borderlessButton)
72+
.menuIndicator(.hidden)
73+
}
74+
.onReceive(codeFile.$wrapLines) { _ in // This is annoying but it works
75+
refreshToggleBool.toggle()
76+
}
77+
}
78+
3379
var splitviewButton: some View {
3480
Group {
3581
switch (editor.parent?.axis, modifierKeys.contains(.option)) {
@@ -53,9 +99,6 @@ struct EditorTabBarTrailingAccessories: View {
5399
EmptyView()
54100
}
55101
}
56-
.buttonStyle(.icon)
57-
.disabled(editorManager.isFocusingActiveEditor)
58-
.opacity(editorManager.isFocusingActiveEditor ? 0.5 : 1)
59102
}
60103

61104
func split(edge: Edge) {

CodeEdit/Features/Editor/Views/CodeFileView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct CodeFileView: View {
4444
var bracketEmphasis
4545
@AppSettings(\.textEditing.useSystemCursor)
4646
var useSystemCursor
47+
@AppSettings(\.textEditing.showMinimap)
48+
var showMinimap
4749

4850
@Environment(\.colorScheme)
4951
private var colorScheme
@@ -125,7 +127,8 @@ struct CodeFileView: View {
125127
bracketPairEmphasis: getBracketPairEmphasis(),
126128
useSystemCursor: useSystemCursor,
127129
undoManager: undoManager,
128-
coordinators: textViewCoordinators
130+
coordinators: textViewCoordinators,
131+
showMinimap: showMinimap
129132
)
130133
.id(codeFile.fileURL)
131134
.background {

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ extension SettingsData {
2727
"Autocomplete braces",
2828
"Enable type-over completion",
2929
"Bracket Pair Emphasis",
30-
"Bracket Pair Highlight"
30+
"Bracket Pair Highlight",
31+
"Show Minimap",
3132
]
3233
if #available(macOS 14.0, *) {
3334
keys.append("System Cursor")
@@ -70,6 +71,9 @@ extension SettingsData {
7071
/// Use the system cursor for the source editor.
7172
var useSystemCursor: Bool = true
7273

74+
/// Toggle the minimap in the editor.
75+
var showMinimap: Bool = true
76+
7377
/// Default initializer
7478
init() {
7579
self.populateCommands()
@@ -118,6 +122,8 @@ extension SettingsData {
118122
self.useSystemCursor = false
119123
}
120124

125+
self.showMinimap = try container.decodeIfPresent(Bool.self, forKey: .showMinimap) ?? true
126+
121127
self.populateCommands()
122128
}
123129

@@ -130,7 +136,7 @@ extension SettingsData {
130136
title: "Toggle Type-Over Completion",
131137
id: "prefs.text_editing.type_over_completion",
132138
command: {
133-
Settings.shared.preferences.textEditing.enableTypeOverCompletion.toggle()
139+
Settings[\.textEditing].enableTypeOverCompletion.toggle()
134140
}
135141
)
136142

@@ -139,7 +145,7 @@ extension SettingsData {
139145
title: "Toggle Autocomplete Braces",
140146
id: "prefs.text_editing.autocomplete_braces",
141147
command: {
142-
Settings.shared.preferences.textEditing.autocompleteBraces.toggle()
148+
Settings[\.textEditing].autocompleteBraces.toggle()
143149
}
144150
)
145151

@@ -151,6 +157,14 @@ extension SettingsData {
151157
Settings[\.textEditing].wrapLinesToEditorWidth.toggle()
152158
}
153159
)
160+
161+
mgr.addCommand(
162+
name: "Toggle Minimap",
163+
title: "Toggle Minimap",
164+
id: "prefs.text_editing.toggle_minimap"
165+
) {
166+
Settings[\.textEditing].showMinimap.toggle()
167+
}
154168
}
155169

156170
struct IndentOption: Codable, Hashable {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct TextEditingSettingsView: View {
2020
wrapLinesToEditorWidth
2121
useSystemCursor
2222
overscroll
23+
showMinimap
2324
}
2425
Section {
2526
fontSelector
@@ -199,4 +200,10 @@ private extension TextEditingSettingsView {
199200
}
200201
}
201202
}
203+
204+
@ViewBuilder private var showMinimap: some View {
205+
Toggle("Show Minimap", isOn: $textEditing.showMinimap)
206+
// swiftlint:disable:next line_length
207+
.help("The minimap gives you a high-level summary of your source code, with controls to quickly navigate your document.")
208+
}
202209
}

0 commit comments

Comments
 (0)