Skip to content

Add A Minimap #2032

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 27, 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
6 changes: 3 additions & 3 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" */,
6CFE18222DA59C9F00A7B796 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
6CF368562DBBD274006A77FD /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
);
preferredProjectObjectVersion = 55;
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
Expand Down Expand Up @@ -1745,12 +1745,12 @@
version = 1.0.1;
};
};
6CFE18222DA59C9F00A7B796 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
6CF368562DBBD274006A77FD /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/CodeEditApp/CodeEditSourceEditor";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.11.0;
minimumVersion = 0.12.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditSourceEditor",
"state" : {
"revision" : "f444927ab70015f4b76f119f6fc5d0e358fcd77a",
"version" : "0.11.0"
"revision" : "412b0a26cbeb3f3148a1933dd598c976defe92a6",
"version" : "0.12.0"
}
},
{
Expand All @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditTextView.git",
"state" : {
"revision" : "47faec9fb571c9c695897e69f0a4f08512ae682e",
"version" : "0.8.2"
"revision" : "a5912e60f6bac25cd1cdf8bb532e1125b21cf7f7",
"version" : "0.10.1"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ struct EditorJumpBarView: View {
@Environment(\.controlActiveState)
private var activeState

@Binding var codeFile: CodeFileDocument?

static let height = 28.0

init(
file: CEWorkspaceFile?,
shouldShowTabBar: Bool,
codeFile: Binding<CodeFileDocument?>,
tappedOpenFile: @escaping (CEWorkspaceFile) -> Void
) {
self.file = file ?? nil
self.shouldShowTabBar = shouldShowTabBar
self._codeFile = codeFile
self.tappedOpenFile = tappedOpenFile
}

Expand Down Expand Up @@ -75,7 +79,7 @@ struct EditorJumpBarView: View {
}
.safeAreaInset(edge: .trailing, spacing: 0) {
if !shouldShowTabBar {
EditorTabBarTrailingAccessories()
EditorTabBarTrailingAccessories(codeFile: $codeFile)
}
}
.frame(height: Self.height, alignment: .center)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import SwiftUI

struct EditorTabBarTrailingAccessories: View {
@AppSettings(\.textEditing.wrapLinesToEditorWidth)
var wrapLinesToEditorWidth
@AppSettings(\.textEditing.showMinimap)
var showMinimap

@Environment(\.splitEditor)
var splitEditor

Expand All @@ -21,15 +26,49 @@ struct EditorTabBarTrailingAccessories: View {

@EnvironmentObject private var editor: Editor

@Binding var codeFile: CodeFileDocument?

var body: some View {
HStack(spacing: 0) {
HStack(spacing: 6) {
// Once more options are implemented that are available for non-code documents, remove this if statement
if let codeFile {
editorOptionsMenu(codeFile: codeFile)
Divider()
.padding(.vertical, 10)
}
splitviewButton
}
.buttonStyle(.icon)
.disabled(editorManager.isFocusingActiveEditor)
.opacity(editorManager.isFocusingActiveEditor ? 0.5 : 1)
.padding(.horizontal, 7)
.opacity(activeState != .inactive ? 1.0 : 0.5)
.frame(maxHeight: .infinity) // Fill out vertical spaces.
}

func editorOptionsMenu(codeFile: CodeFileDocument) -> some View {
// This is a button so it gets the same styling from the Group in `body`.
Button(action: {}, label: { Image(systemName: "slider.horizontal.3") })
.overlay {
Menu {
Toggle("Show Minimap", isOn: $showMinimap)
.keyboardShortcut("M", modifiers: [.command, .shift, .control])
Divider()
Toggle(
"Wrap Lines",
isOn: Binding(
get: { codeFile.wrapLines ?? wrapLinesToEditorWidth },
set: {
codeFile.wrapLines = $0
}
)
)
} label: {}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
}
}

var splitviewButton: some View {
Group {
switch (editor.parent?.axis, modifierKeys.contains(.option)) {
Expand All @@ -53,9 +92,6 @@ struct EditorTabBarTrailingAccessories: View {
EmptyView()
}
}
.buttonStyle(.icon)
.disabled(editorManager.isFocusingActiveEditor)
.opacity(editorManager.isFocusingActiveEditor ? 0.5 : 1)
}

func split(edge: Edge) {
Expand All @@ -73,6 +109,6 @@ struct EditorTabBarTrailingAccessories: View {

struct TabBarTrailingAccessories_Previews: PreviewProvider {
static var previews: some View {
EditorTabBarTrailingAccessories()
EditorTabBarTrailingAccessories(codeFile: .constant(nil))
}
}
3 changes: 2 additions & 1 deletion CodeEdit/Features/Editor/TabBar/Views/EditorTabBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct EditorTabBarView: View {
let hasTopInsets: Bool
@Binding var codeFile: CodeFileDocument?
/// The height of tab bar.
/// I am not making it a private variable because it may need to be used in outside views.
static let height = 28.0
Expand All @@ -21,7 +22,7 @@ struct EditorTabBarView: View {
.accessibilityElement(children: .contain)
.accessibilityLabel("Tab Bar")
.accessibilityIdentifier("TabBar")
EditorTabBarTrailingAccessories()
EditorTabBarTrailingAccessories(codeFile: $codeFile)
.padding(.top, hasTopInsets ? -1 : 0)
}
.frame(height: EditorTabBarView.height - (hasTopInsets ? 1 : 0))
Expand Down
5 changes: 4 additions & 1 deletion CodeEdit/Features/Editor/Views/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct CodeFileView: View {
var bracketEmphasis
@AppSettings(\.textEditing.useSystemCursor)
var useSystemCursor
@AppSettings(\.textEditing.showMinimap)
var showMinimap

@Environment(\.colorScheme)
private var colorScheme
Expand Down Expand Up @@ -125,7 +127,8 @@ struct CodeFileView: View {
bracketPairEmphasis: getBracketPairEmphasis(),
useSystemCursor: useSystemCursor,
undoManager: undoManager,
coordinators: textViewCoordinators
coordinators: textViewCoordinators,
showMinimap: showMinimap
)
.id(codeFile.fileURL)
.background {
Expand Down
5 changes: 3 additions & 2 deletions CodeEdit/Features/Editor/Views/EditorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ struct EditorAreaView: View {
.background(.clear)
}
if shouldShowTabBar {
EditorTabBarView(hasTopInsets: topSafeArea > 0)
EditorTabBarView(hasTopInsets: topSafeArea > 0, codeFile: $codeFile)
.id("TabBarView" + editor.id.uuidString)
.environmentObject(editor)
Divider()
}
if showEditorJumpBar {
EditorJumpBarView(
file: editor.selectedTab?.file,
shouldShowTabBar: shouldShowTabBar
shouldShowTabBar: shouldShowTabBar,
codeFile: $codeFile
) { [weak editor] newFile in
if let file = editor?.selectedTab, let index = editor?.tabs.firstIndex(of: file) {
editor?.openTab(file: newFile, at: index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ extension SettingsData {
"Autocomplete braces",
"Enable type-over completion",
"Bracket Pair Emphasis",
"Bracket Pair Highlight"
"Bracket Pair Highlight",
"Show Minimap",
]
if #available(macOS 14.0, *) {
keys.append("System Cursor")
Expand Down Expand Up @@ -70,6 +71,9 @@ extension SettingsData {
/// Use the system cursor for the source editor.
var useSystemCursor: Bool = true

/// Toggle the minimap in the editor.
var showMinimap: Bool = true

/// Default initializer
init() {
self.populateCommands()
Expand Down Expand Up @@ -118,6 +122,8 @@ extension SettingsData {
self.useSystemCursor = false
}

self.showMinimap = try container.decodeIfPresent(Bool.self, forKey: .showMinimap) ?? true

self.populateCommands()
}

Expand All @@ -130,7 +136,7 @@ extension SettingsData {
title: "Toggle Type-Over Completion",
id: "prefs.text_editing.type_over_completion",
command: {
Settings.shared.preferences.textEditing.enableTypeOverCompletion.toggle()
Settings[\.textEditing].enableTypeOverCompletion.toggle()
}
)

Expand All @@ -139,7 +145,7 @@ extension SettingsData {
title: "Toggle Autocomplete Braces",
id: "prefs.text_editing.autocomplete_braces",
command: {
Settings.shared.preferences.textEditing.autocompleteBraces.toggle()
Settings[\.textEditing].autocompleteBraces.toggle()
}
)

Expand All @@ -151,6 +157,14 @@ extension SettingsData {
Settings[\.textEditing].wrapLinesToEditorWidth.toggle()
}
)

mgr.addCommand(
name: "Toggle Minimap",
title: "Toggle Minimap",
id: "prefs.text_editing.toggle_minimap"
) {
Settings[\.textEditing].showMinimap.toggle()
}
}

struct IndentOption: Codable, Hashable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct TextEditingSettingsView: View {
wrapLinesToEditorWidth
useSystemCursor
overscroll
showMinimap
}
Section {
fontSelector
Expand Down Expand Up @@ -199,4 +200,10 @@ private extension TextEditingSettingsView {
}
}
}

@ViewBuilder private var showMinimap: some View {
Toggle("Show Minimap", isOn: $textEditing.showMinimap)
// swiftlint:disable:next line_length
.help("The minimap gives you a high-level summary of your source code, with controls to quickly navigate your document.")
}
}