-
Notifications
You must be signed in to change notification settings - Fork 97
Minimap #302
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
Minimap #302
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
cb422bb
Render A Minimap
thecoolwinter 17035f6
Correctly Wrap Lines, Render Line Breaks, Add to ScrollView
thecoolwinter 39867e9
Merge branch 'main' into feat/minimap
thecoolwinter a8928ed
Start on Scrolling Offset
thecoolwinter a08aee6
Merge branch 'main' into feat/minimap
thecoolwinter 95e0b91
Scroll Syncing Done!
thecoolwinter 6cf5e5f
Move to Under Scroller, Performance Improvements
thecoolwinter ef2f8f0
Make Scroller on Top, Utilize Content Insets
thecoolwinter b7f341f
Overscroll, Finalize Mouse Interaction, Document Everything
thecoolwinter b5c4f8a
Draw Selections
thecoolwinter da173ae
Small Bugfix with Selection Drawing
thecoolwinter 98808d5
Toggle Minimap
thecoolwinter 306eed3
Merge branch 'main' into feat/minimap
thecoolwinter 8976e1f
Docs & Linter
thecoolwinter ffdb740
Fix More Scrolling Edge Cases
thecoolwinter d6fd1eb
Accidental Blue!
thecoolwinter 00bcea1
Update Positions On Layout, Linting Fixes
thecoolwinter 2fdbed0
Layout on WillAppear
thecoolwinter 4f4de36
Correctly Call Layout
thecoolwinter 58030bb
Docs, Tests
thecoolwinter fa69a42
Update MinimapView.swift
thecoolwinter f9f260e
Bump CodeEditTextView
thecoolwinter 8eef187
Update Package.resolved
thecoolwinter c688bcb
Use Constraint For Minimap ContentView Height
thecoolwinter 6f605a2
Move to `styleMinimapView`
thecoolwinter e3a774e
Rename to StatusBar
thecoolwinter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
...itSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/Toolbar.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// | ||
thecoolwinter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Toolbar.swift | ||
// CodeEditSourceEditorExample | ||
// | ||
// Created by Khan Winter on 4/17/25. | ||
// | ||
|
||
import SwiftUI | ||
import CodeEditSourceEditor | ||
import CodeEditLanguages | ||
|
||
struct Toolbar: View { | ||
let fileURL: URL? | ||
|
||
@Environment(\.colorScheme) | ||
var colorScheme | ||
|
||
@Binding var document: CodeEditSourceEditorExampleDocument | ||
@Binding var wrapLines: Bool | ||
@Binding var useSystemCursor: Bool | ||
@Binding var cursorPositions: [CursorPosition] | ||
@Binding var isInLongParse: Bool | ||
@Binding var language: CodeLanguage | ||
@Binding var theme: EditorTheme | ||
@Binding var showMinimap: Bool | ||
@Binding var indentOption: IndentOption | ||
|
||
var body: some View { | ||
HStack { | ||
Menu { | ||
Toggle("Wrap Lines", isOn: $wrapLines) | ||
Toggle("Show Minimap", isOn: $showMinimap) | ||
if #available(macOS 14, *) { | ||
Toggle("Use System Cursor", isOn: $useSystemCursor) | ||
} else { | ||
Toggle("Use System Cursor", isOn: $useSystemCursor) | ||
.disabled(true) | ||
.help("macOS 14 required") | ||
} | ||
} label: {} | ||
.background { | ||
Image(systemName: "switch.2") | ||
.foregroundStyle(.secondary) | ||
.font(.system(size: 13.5, weight: .regular)) | ||
} | ||
.menuStyle(.borderlessButton) | ||
.menuIndicator(.hidden) | ||
.frame(maxWidth: 18, alignment: .center) | ||
|
||
Spacer() | ||
|
||
Group { | ||
if isInLongParse { | ||
HStack(spacing: 5) { | ||
ProgressView() | ||
.controlSize(.small) | ||
Text("Parsing Document") | ||
} | ||
} else { | ||
Text(getLabel(cursorPositions)) | ||
} | ||
} | ||
.foregroundStyle(.secondary) | ||
Divider() | ||
.frame(height: 12) | ||
LanguagePicker(language: $language) | ||
.buttonStyle(.borderless) | ||
IndentPicker(indentOption: $indentOption, enabled: document.text.isEmpty) | ||
.buttonStyle(.borderless) | ||
} | ||
.font(.subheadline) | ||
.fontWeight(.medium) | ||
.controlSize(.small) | ||
.padding(.horizontal, 8) | ||
.frame(height: 28) | ||
.background(.bar) | ||
.overlay(alignment: .top) { | ||
VStack { | ||
Divider() | ||
.overlay { | ||
if colorScheme == .dark { | ||
Color.black | ||
} | ||
} | ||
} | ||
} | ||
.zIndex(2) | ||
.onAppear { | ||
self.language = detectLanguage(fileURL: fileURL) ?? .default | ||
self.theme = colorScheme == .dark ? .dark : .light | ||
} | ||
} | ||
|
||
private func detectLanguage(fileURL: URL?) -> CodeLanguage? { | ||
guard let fileURL else { return nil } | ||
return CodeLanguage.detectLanguageFrom( | ||
url: fileURL, | ||
prefixBuffer: document.text.getFirstLines(5), | ||
suffixBuffer: document.text.getLastLines(5) | ||
) | ||
} | ||
|
||
/// Create a label string for cursor positions. | ||
/// - Parameter cursorPositions: The cursor positions to create the label for. | ||
/// - Returns: A string describing the user's location in a document. | ||
func getLabel(_ cursorPositions: [CursorPosition]) -> String { | ||
if cursorPositions.isEmpty { | ||
return "No cursor" | ||
} | ||
|
||
// More than one selection, display the number of selections. | ||
if cursorPositions.count > 1 { | ||
return "\(cursorPositions.count) selected ranges" | ||
} | ||
|
||
// When there's a single cursor, display the line and column. | ||
return "Line: \(cursorPositions[0].line) Col: \(cursorPositions[0].column) Range: \(cursorPositions[0].range)" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.