Skip to content

Commit 95fad7e

Browse files
committed
Make the min width adjustable
1 parent 16ba72e commit 95fad7e

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

Copilot for Xcode/SettingsView.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct SettingsView: View {
2424
var suggestionFeatureEnabledProjectList: [String]
2525
@AppStorage(\.promptToCodeFeatureProvider)
2626
var promptToCodeFeatureProvider: PromptToCodeFeatureProvider
27+
@AppStorage(\.preferWidgetToStayInsideEditorWhenWidthGreaterThan)
28+
var preferWidgetToStayInsideEditorWhenWidthGreaterThan: Double
2729
init() {}
2830
}
2931

@@ -136,7 +138,7 @@ struct SettingsView: View {
136138
Text("Use accessibility API to accept suggestion in widget")
137139
}
138140
.toggleStyle(.switch)
139-
141+
140142
Picker(selection: $settings.promptToCodeFeatureProvider) {
141143
ForEach(PromptToCodeFeatureProvider.allCases, id: \.rawValue) {
142144
switch $0 {
@@ -149,6 +151,21 @@ struct SettingsView: View {
149151
} label: {
150152
Text("Prompt to code with")
151153
}
154+
155+
HStack {
156+
TextField(text: .init(get: {
157+
"\(Int(settings.preferWidgetToStayInsideEditorWhenWidthGreaterThan))"
158+
}, set: {
159+
settings
160+
.preferWidgetToStayInsideEditorWhenWidthGreaterThan =
161+
Double(Int($0) ?? 0)
162+
})) {
163+
Text("Prefer widget to be inside editor when width greater than")
164+
}
165+
.textFieldStyle(.roundedBorder)
166+
167+
Text("px")
168+
}
152169
}
153170
}.buttonStyle(.copilot)
154171
}
@@ -209,7 +226,7 @@ struct SuggestionFeatureEnabledProjectListView: View {
209226
}
210227
}
211228
Spacer()
212-
229+
213230
Button(action: {
214231
settings.suggestionFeatureEnabledProjectList.removeAll(
215232
where: { $0 == project }
@@ -247,7 +264,9 @@ struct SuggestionFeatureAddEnabledProjectView: View {
247264

248265
var body: some View {
249266
VStack {
250-
Text("Enter the root path of the project. Do not use `~` to replace /Users/yourUserName.")
267+
Text(
268+
"Enter the root path of the project. Do not use `~` to replace /Users/yourUserName."
269+
)
251270
TextField("Root path", text: $rootPath)
252271
HStack {
253272
Spacer()

Core/Sources/Preferences/Keys.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public struct UserDefaultPreferenceKeys {
124124
public var hideCommonPrecedingSpacesInSuggestion: HideCommonPrecedingSpacesInSuggestion {
125125
.init()
126126
}
127-
127+
128128
public struct ForceOrderWidgetToFront: UserDefaultPreferenceKey {
129129
public let defaultValue = true
130130
public let key = "ForceOrderWidgetToFront"
@@ -133,34 +133,43 @@ public struct UserDefaultPreferenceKeys {
133133
public var forceOrderWidgetToFront: HideCommonPrecedingSpacesInSuggestion {
134134
.init()
135135
}
136-
136+
137137
public struct DisableSuggestionFeatureGlobally: UserDefaultPreferenceKey {
138138
public let defaultValue = false
139139
public let key = "DisableSuggestionFeatureGlobally"
140140
}
141-
141+
142142
public var disableSuggestionFeatureGlobally: DisableSuggestionFeatureGlobally {
143143
.init()
144144
}
145-
145+
146146
public struct SuggestionFeatureEnabledProjectList: UserDefaultPreferenceKey {
147147
public let defaultValue: [String] = []
148148
public let key = "SuggestionFeatureEnabledProjectList"
149149
}
150-
150+
151151
public var suggestionFeatureEnabledProjectList: SuggestionFeatureEnabledProjectList {
152152
.init()
153153
}
154-
154+
155155
public struct PromptToCodeFeatureProviderKey: UserDefaultPreferenceKey {
156156
public let defaultValue: PromptToCodeFeatureProvider = .openAI
157157
public let key = "PromptToCodeFeatureProvider"
158158
}
159-
159+
160160
public var promptToCodeFeatureProvider: PromptToCodeFeatureProviderKey {
161161
.init()
162162
}
163163

164+
public struct PreferWidgetToStayInsideEditorWhenWidthGreaterThan: UserDefaultPreferenceKey {
165+
public let defaultValue = 1400 as Double
166+
public let key = "PreferWidgetToStayInsideEditorWhenWidthGreaterThan"
167+
}
168+
169+
public var preferWidgetToStayInsideEditorWhenWidthGreaterThan: PreferWidgetToStayInsideEditorWhenWidthGreaterThan {
170+
.init()
171+
}
172+
164173
public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() }
165174
public var preCacheOnFileOpen: FeatureFlags.PreCacheOnFileOpen { .init() }
166175
}
@@ -170,7 +179,7 @@ public enum FeatureFlags {
170179
public let defaultValue = false
171180
public let key = "FeatureFlag-DisableLazyVStack"
172181
}
173-
182+
174183
public struct PreCacheOnFileOpen: UserDefaultPreferenceKey {
175184
public let defaultValue = true
176185
public let key = "FeatureFlag-PreCacheOnFileOpen"

Core/Sources/SuggestionWidget/WidgetPositionStrategy.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ enum UpdateLocationStrategy {
8080
tabFrame: CGRect,
8181
alignPanelTopToAnchor: Bool
8282
) {
83-
let preferredInsideEditorMinWidth = 1400 as Double
84-
83+
let preferredInsideEditorMinWidth = UserDefaults.shared
84+
.value(for: \.preferWidgetToStayInsideEditorWhenWidthGreaterThan)
85+
8586
let maxY = max(
8687
y,
8788
mainScreen.frame.height - editorFrame.maxY + Style.widgetPadding,

0 commit comments

Comments
 (0)