Skip to content

Commit 14167e9

Browse files
committed
Add settings to turn hide common preceding spaces on
1 parent d7992c3 commit 14167e9

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

Core/Sources/Preferences/Keys.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ public struct UserDefaultPreferenceKeys {
116116

117117
public var useGlobalChat: UseGlobalChat { .init() }
118118

119+
public struct HideCommonPrecedingSpacesInSuggestion: UserDefaultPreferenceKey {
120+
public let defaultValue = false
121+
public let key = "HideCommonPrecedingSpacesInSuggestion"
122+
}
123+
124+
public var hideCommonPrecedingSpacesInSuggestion: HideCommonPrecedingSpacesInSuggestion {
125+
.init()
126+
}
127+
119128
public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() }
120129
}
121130

Core/Sources/SuggestionWidget/SuggestionPanelContent/CodeBlockSuggestionPanel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct CodeBlock: View {
1919
.multilineTextAlignment(.leading)
2020
.lineSpacing(4)
2121
.overlay(alignment: .topLeading) {
22-
if index == 0 {
22+
if index == 0, suggestion.commonPrecedingSpaceCount > 0 {
2323
Text("\(suggestion.commonPrecedingSpaceCount + 1)")
2424
.padding(.top, -12)
2525
.font(.footnote)

Core/Sources/SuggestionWidget/SuggestionProvider.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ public final class SuggestionProvider: ObservableObject {
55
@Published public var code: String = "" {
66
didSet { highlightedCode = nil }
77
}
8+
89
@Published public var language: String = "" {
910
didSet { highlightedCode = nil }
1011
}
12+
1113
@Published public var startLineIndex: Int = 0
1214
@Published public var suggestionCount: Int = 0
1315
@Published public var currentSuggestionIndex: Int = 0
1416
@Published public var commonPrecedingSpaceCount = 0
15-
17+
1618
private var colorScheme: ColorScheme = .light
17-
private var highlightedCode: [NSAttributedString]? = nil
18-
19+
private var highlightedCode: [NSAttributedString]?
20+
1921
func highlightedCode(colorScheme: ColorScheme) -> [NSAttributedString] {
2022
if colorScheme != self.colorScheme { highlightedCode = nil }
2123
self.colorScheme = colorScheme
@@ -24,15 +26,16 @@ public final class SuggestionProvider: ObservableObject {
2426
code: code,
2527
language: language,
2628
brightMode: colorScheme != .dark,
27-
droppingLeadingSpaces: true
29+
droppingLeadingSpaces: UserDefaults.shared
30+
.value(for: \.hideCommonPrecedingSpacesInSuggestion)
2831
)
2932
highlightedCode = new
3033
Task { @MainActor in
3134
commonPrecedingSpaceCount = spaceCount
3235
}
3336
return new
3437
}
35-
38+
3639
public var onSelectPreviousSuggestionTapped: () -> Void
3740
public var onSelectNextSuggestionTapped: () -> Void
3841
public var onRejectSuggestionTapped: () -> Void

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct WidgetContextMenu: View {
9393
@AppStorage(\.useGlobalChat) var useGlobalChat
9494
@AppStorage(\.realtimeSuggestionToggle) var realtimeSuggestionToggle
9595
@AppStorage(\.acceptSuggestionWithAccessibilityAPI) var acceptSuggestionWithAccessibilityAPI
96+
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion) var hideCommonPrecedingSpacesInSuggestion
9697

9798
var body: some View {
9899
Group {
@@ -123,6 +124,15 @@ struct WidgetContextMenu: View {
123124
}
124125
})
125126

127+
Button(action: {
128+
hideCommonPrecedingSpacesInSuggestion.toggle()
129+
}, label: {
130+
Text("Hide Common Preceding Spaces in Suggestion")
131+
if hideCommonPrecedingSpacesInSuggestion {
132+
Image(systemName: "checkmark")
133+
}
134+
})
135+
126136
Divider()
127137

128138
Button(action: {

0 commit comments

Comments
 (0)