Skip to content

Commit dff5d89

Browse files
committed
Merge branch 'feature/font-size-adjustment-prompt-to-code' into develop
2 parents 7991c9d + c339de7 commit dff5d89

8 files changed

Lines changed: 54 additions & 35 deletions

File tree

Core/Sources/HostApp/FeatureSettings/PromptToCodeSettingsView.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import ProHostApp
88

99
struct PromptToCodeSettingsView: View {
1010
final class Settings: ObservableObject {
11-
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion)
12-
var hideCommonPrecedingSpacesInSuggestion
13-
@AppStorage(\.suggestionCodeFontSize)
14-
var suggestionCodeFontSize
11+
@AppStorage(\.hideCommonPrecedingSpacesInPromptToCode)
12+
var hideCommonPrecedingSpaces
13+
@AppStorage(\.promptToCodeCodeFontSize)
14+
var fontSize
1515
@AppStorage(\.promptToCodeGenerateDescription)
1616
var promptToCodeGenerateDescription
1717
@AppStorage(\.promptToCodeGenerateDescriptionInUserPreferredLanguage)
@@ -84,25 +84,25 @@ struct PromptToCodeSettingsView: View {
8484
}
8585
}
8686

87-
SettingsDivider("Mirroring Settings of Suggestion Feature")
87+
SettingsDivider("UI")
8888

8989
Form {
90-
Toggle(isOn: $settings.hideCommonPrecedingSpacesInSuggestion) {
90+
Toggle(isOn: $settings.hideCommonPrecedingSpaces) {
9191
Text("Hide Common Preceding Spaces")
92-
}.disabled(true)
92+
}
9393

9494
HStack {
9595
TextField(text: .init(get: {
96-
"\(Int(settings.suggestionCodeFontSize))"
96+
"\(Int(settings.fontSize))"
9797
}, set: {
98-
settings.suggestionCodeFontSize = Double(Int($0) ?? 0)
98+
settings.fontSize = Double(Int($0) ?? 0)
9999
})) {
100100
Text("Font size of suggestion code")
101101
}
102102
.textFieldStyle(.roundedBorder)
103103

104104
Text("pt")
105-
}.disabled(true)
105+
}
106106
}
107107

108108
ScopeForm()

Core/Sources/SuggestionWidget/SuggestionPanelContent/CodeBlockSuggestionPanel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct CodeBlockSuggestionPanel: View {
77
@AppStorage(\.suggestionCodeFontSize) var fontSize
88
@AppStorage(\.suggestionDisplayCompactMode) var suggestionDisplayCompactMode
99
@AppStorage(\.suggestionPresentationMode) var suggestionPresentationMode
10+
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion) var hideCommonPrecedingSpaces
1011

1112
struct ToolBar: View {
1213
@ObservedObject var suggestion: CodeSuggestionProvider
@@ -101,7 +102,8 @@ struct CodeBlockSuggestionPanel: View {
101102
language: suggestion.language,
102103
startLineIndex: suggestion.startLineIndex,
103104
colorScheme: colorScheme,
104-
fontSize: fontSize
105+
fontSize: fontSize,
106+
droppingLeadingSpaces: hideCommonPrecedingSpaces
105107
)
106108
.frame(maxWidth: .infinity)
107109
}

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ extension PromptToCodePanel {
202202
struct Content: View {
203203
let store: StoreOf<PromptToCode>
204204
@Environment(\.colorScheme) var colorScheme
205-
@AppStorage(\.suggestionCodeFontSize) var fontSize
205+
@AppStorage(\.promptToCodeCodeFontSize) var fontSize
206+
@AppStorage(\.hideCommonPrecedingSpacesInPromptToCode) var hideCommonPrecedingSpaces
206207

207208
struct CodeContent: Equatable {
208209
var code: String
@@ -278,7 +279,8 @@ extension PromptToCodePanel {
278279
colorScheme: colorScheme,
279280
firstLinePrecedingSpaceCount: viewStore.state
280281
.firstLinePrecedingSpaceCount,
281-
fontSize: fontSize
282+
fontSize: fontSize,
283+
droppingLeadingSpaces: hideCommonPrecedingSpaces
282284
)
283285
.frame(maxWidth: .infinity)
284286
.scaleEffect(x: 1, y: -1, anchor: .center)

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ struct WidgetAnimatedCircle: View {
140140
struct WidgetContextMenu: View {
141141
@AppStorage(\.useGlobalChat) var useGlobalChat
142142
@AppStorage(\.realtimeSuggestionToggle) var realtimeSuggestionToggle
143-
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion) var hideCommonPrecedingSpacesInSuggestion
144143
@AppStorage(\.disableSuggestionFeatureGlobally) var disableSuggestionFeatureGlobally
145144
@AppStorage(\.suggestionFeatureEnabledProjectList) var suggestionFeatureEnabledProjectList
146145
@AppStorage(\.suggestionFeatureDisabledLanguageList) var suggestionFeatureDisabledLanguageList
@@ -198,15 +197,6 @@ struct WidgetContextMenu: View {
198197
Image(systemName: "checkmark")
199198
}
200199
}
201-
202-
Button(action: {
203-
hideCommonPrecedingSpacesInSuggestion.toggle()
204-
}, label: {
205-
Text("Hide Common Preceding Spaces in Suggestion")
206-
if hideCommonPrecedingSpacesInSuggestion {
207-
Image(systemName: "checkmark")
208-
}
209-
})
210200
}
211201

212202
Divider()

Tool/Sources/Preferences/Keys.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ public extension UserDefaultPreferenceKeys {
294294
var enableSenseScopeByDefaultInPromptToCode: PreferenceKey<Bool> {
295295
.init(defaultValue: false, key: "EnableSenseScopeByDefaultInPromptToCode")
296296
}
297+
298+
var promptToCodeCodeFontSize: PreferenceKey<Double> {
299+
.init(defaultValue: 13, key: "PromptToCodeCodeFontSize")
300+
}
301+
302+
var hideCommonPrecedingSpacesInPromptToCode: PreferenceKey<Bool> {
303+
.init(defaultValue: true, key: "HideCommonPrecedingSpacesInPromptToCode")
304+
}
297305
}
298306

299307
// MARK: - Suggestion

Tool/Sources/Preferences/UserDefaults.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public extension UserDefaults {
2525
for: \.suggestionFeatureProvider,
2626
defaultValue: .builtIn(shared.deprecatedValue(for: \.oldSuggestionFeatureProvider))
2727
)
28+
shared.setupDefaultValue(
29+
for: \.promptToCodeCodeFontSize,
30+
defaultValue: shared.value(for: \.suggestionCodeFontSize)
31+
)
2832
}
2933
}
3034

Tool/Sources/SharedUIComponents/CodeBlock.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ public struct CodeBlock: View {
99
public let highlightedCode: [NSAttributedString]
1010
public let firstLinePrecedingSpaceCount: Int
1111
public let fontSize: Double
12+
public let droppingLeadingSpaces: Bool
1213

1314
public init(
1415
code: String,
1516
language: String,
1617
startLineIndex: Int,
1718
colorScheme: ColorScheme,
1819
firstLinePrecedingSpaceCount: Int = 0,
19-
fontSize: Double
20+
fontSize: Double,
21+
droppingLeadingSpaces: Bool
2022
) {
2123
self.code = code
2224
self.language = language
2325
self.startLineIndex = startLineIndex
2426
self.colorScheme = colorScheme
27+
self.droppingLeadingSpaces = droppingLeadingSpaces
2528
self.firstLinePrecedingSpaceCount = firstLinePrecedingSpaceCount
2629
self.fontSize = fontSize
2730
let padding = firstLinePrecedingSpaceCount > 0
@@ -31,7 +34,8 @@ public struct CodeBlock: View {
3134
code: padding + code,
3235
language: language,
3336
colorScheme: colorScheme,
34-
fontSize: fontSize
37+
fontSize: fontSize,
38+
droppingLeadingSpaces: droppingLeadingSpaces
3539
)
3640
commonPrecedingSpaceCount = result.commonLeadingSpaceCount
3741
highlightedCode = result.code
@@ -72,14 +76,14 @@ public struct CodeBlock: View {
7276
code: String,
7377
language: String,
7478
colorScheme: ColorScheme,
75-
fontSize: Double
79+
fontSize: Double,
80+
droppingLeadingSpaces: Bool
7681
) -> (code: [NSAttributedString], commonLeadingSpaceCount: Int) {
7782
return highlighted(
7883
code: code,
7984
language: language,
8085
brightMode: colorScheme != .dark,
81-
droppingLeadingSpaces: UserDefaults.shared
82-
.value(for: \.hideCommonPrecedingSpacesInSuggestion),
86+
droppingLeadingSpaces: droppingLeadingSpaces,
8387
fontSize: fontSize
8488
)
8589
}
@@ -98,7 +102,8 @@ struct CodeBlock_Previews: PreviewProvider {
98102
startLineIndex: 0,
99103
colorScheme: .dark,
100104
firstLinePrecedingSpaceCount: 0,
101-
fontSize: 12
105+
fontSize: 12,
106+
droppingLeadingSpaces: true
102107
)
103108
}
104109
}

Tool/Sources/SharedUIComponents/Experiment/NewCodeBlock.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct _CodeBlock: View {
1212
let commonPrecedingSpaceCount: Int
1313
let highlightedCode: AttributedString
1414
let colorScheme: ColorScheme
15+
let droppingLeadingSpaces: Bool
1516

1617
/// Create a text edit view with a certain text that uses a certain options.
1718
/// - Parameters:
@@ -24,11 +25,13 @@ struct _CodeBlock: View {
2425
firstLinePrecedingSpaceCount: Int,
2526
colorScheme: ColorScheme,
2627
fontSize: Double,
28+
droppingLeadingSpaces: Bool,
2729
selection: Binding<NSRange?> = .constant(nil)
2830
) {
2931
_selection = selection
3032
self.fontSize = fontSize
3133
self.colorScheme = colorScheme
34+
self.droppingLeadingSpaces = droppingLeadingSpaces
3235

3336
let padding = firstLinePrecedingSpaceCount > 0
3437
? String(repeating: " ", count: firstLinePrecedingSpaceCount)
@@ -37,7 +40,8 @@ struct _CodeBlock: View {
3740
code: padding + code,
3841
language: language,
3942
colorScheme: colorScheme,
40-
fontSize: fontSize
43+
fontSize: fontSize,
44+
droppingLeadingSpaces: droppingLeadingSpaces
4145
)
4246
commonPrecedingSpaceCount = result.commonLeadingSpaceCount
4347
highlightedCode = result.code
@@ -65,14 +69,14 @@ struct _CodeBlock: View {
6569
code: String,
6670
language: String,
6771
colorScheme: ColorScheme,
68-
fontSize: Double
72+
fontSize: Double,
73+
droppingLeadingSpaces: Bool
6974
) -> (code: AttributedString, commonLeadingSpaceCount: Int) {
7075
let (lines, commonLeadingSpaceCount) = highlighted(
7176
code: code,
7277
language: language,
7378
brightMode: colorScheme != .dark,
74-
droppingLeadingSpaces: UserDefaults.shared
75-
.value(for: \.hideCommonPrecedingSpacesInSuggestion),
79+
droppingLeadingSpaces: droppingLeadingSpaces,
7680
fontSize: fontSize,
7781
replaceSpacesWithMiddleDots: false
7882
)
@@ -142,7 +146,7 @@ private struct _CodeBlockRepresentable: NSViewRepresentable {
142146
context.coordinator.parent = self
143147

144148
let textView = scrollView.documentView as! STTextViewFrameObservable
145-
149+
146150
textView.onHeightChange = onHeightChange
147151
textView.showsInvisibleCharacters = true
148152
textView.textContainer.lineBreakMode = .byCharWrapping
@@ -241,7 +245,10 @@ private class STTextViewFrameObservable: STTextView {
241245
var onHeightChange: ((Double) -> Void)?
242246
func recalculateSize() {
243247
var maxY = 0 as Double
244-
textLayoutManager.enumerateTextLayoutFragments(in: textLayoutManager.documentRange, options: [.ensuresLayout]) { fragment in
248+
textLayoutManager.enumerateTextLayoutFragments(
249+
in: textLayoutManager.documentRange,
250+
options: [.ensuresLayout]
251+
) { fragment in
245252
print(fragment.layoutFragmentFrame)
246253
maxY = max(maxY, fragment.layoutFragmentFrame.maxY)
247254
return true
@@ -287,3 +294,4 @@ private final class ColumnRuler: NSRulerView {
287294
])
288295
}
289296
}
297+

0 commit comments

Comments
 (0)