fix(swift-ios): stabilize model and composer controls
This commit is contained in:
3 files changed
+30
-157
No files matched your search
@@ -6,9 +6,6 @@ struct FeatureComposerView: View {
|
||||
@State private var pathEntries: [FeatureComposerPathEntry] = []
|
||||
@State private var isPathSearchLoading = false
|
||||
@State private var pathSearchError: String?
|
||||
@State private var cursorOffset: Int?
|
||||
@State private var cursorPlacement: FeatureComposerCursorPlacement?
|
||||
|
||||
@Binding private var text: String
|
||||
@Binding private var selection: FeatureSelection?
|
||||
@Binding private var attachments: [FeatureDraftAttachment]
|
||||
@@ -184,9 +181,14 @@ struct FeatureComposerView: View {
|
||||
.padding(.horizontal, 13)
|
||||
}
|
||||
|
||||
composerEditor
|
||||
TextField(
|
||||
isWorking ? "Message to queue…" : "Ask anything…",
|
||||
text: $text,
|
||||
axis: .vertical
|
||||
)
|
||||
.font(T3Typography.composer)
|
||||
.lineLimit(1...7)
|
||||
.focused(focused)
|
||||
.submitLabel(.send)
|
||||
.onSubmit {
|
||||
if canSend { onSend() }
|
||||
@@ -315,34 +317,8 @@ struct FeatureComposerView: View {
|
||||
DailyUXModelOptions.supportsImages(selection: selection, providers: providers)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var composerEditor: some View {
|
||||
if #available(iOS 18.0, *) {
|
||||
FeatureComposerCursorAwareTextField(
|
||||
prompt: isWorking ? "Message to queue…" : "Ask anything…",
|
||||
text: $text,
|
||||
cursorOffset: $cursorOffset,
|
||||
cursorPlacement: cursorPlacement,
|
||||
focused: focused
|
||||
)
|
||||
} else {
|
||||
// SwiftUI does not expose a TextField selection binding before iOS 18.
|
||||
// Keep the native field on iOS 17 instead of replacing it with a brittle
|
||||
// UITextView bridge; its command completion remains end-of-text aware.
|
||||
TextField(
|
||||
isWorking ? "Message to queue…" : "Ask anything…",
|
||||
text: $text,
|
||||
axis: .vertical
|
||||
)
|
||||
.focused(focused)
|
||||
}
|
||||
}
|
||||
|
||||
private var composerTrigger: FeatureComposerTrigger? {
|
||||
if #available(iOS 18.0, *) {
|
||||
return FeatureComposerTriggerParser.detect(in: text, cursorOffset: cursorOffset)
|
||||
}
|
||||
return FeatureComposerTriggerParser.detect(in: text)
|
||||
FeatureComposerTriggerParser.detect(in: text)
|
||||
}
|
||||
|
||||
private var commandMenuItems: [FeatureComposerMenuItem] {
|
||||
@@ -421,17 +397,11 @@ struct FeatureComposerView: View {
|
||||
case let .path(entry):
|
||||
replacement = FeatureComposerFileLinkSerializer.markdownLink(for: entry.path) + " "
|
||||
}
|
||||
let replacementCursorOffset = trigger.range.lowerBound + replacement.count
|
||||
text = FeatureComposerTriggerParser.replacing(
|
||||
trigger.range,
|
||||
in: text,
|
||||
with: replacement
|
||||
)
|
||||
cursorOffset = replacementCursorOffset
|
||||
cursorPlacement = FeatureComposerCursorPlacement(
|
||||
offset: replacementCursorOffset,
|
||||
revision: (cursorPlacement?.revision ?? 0) + 1
|
||||
)
|
||||
pathEntries = []
|
||||
pathSearchError = nil
|
||||
Task { @MainActor in
|
||||
@@ -450,69 +420,6 @@ struct FeatureComposerView: View {
|
||||
|
||||
}
|
||||
|
||||
private struct FeatureComposerCursorPlacement: Equatable {
|
||||
let offset: Int
|
||||
let revision: Int
|
||||
}
|
||||
|
||||
@available(iOS 18.0, *)
|
||||
private struct FeatureComposerCursorAwareTextField: View {
|
||||
let prompt: String
|
||||
@Binding var text: String
|
||||
@Binding var cursorOffset: Int?
|
||||
let cursorPlacement: FeatureComposerCursorPlacement?
|
||||
let focused: FocusState<Bool>.Binding
|
||||
|
||||
@State private var textSelection: TextSelection?
|
||||
|
||||
var body: some View {
|
||||
TextField(
|
||||
prompt,
|
||||
text: $text,
|
||||
selection: $textSelection,
|
||||
axis: .vertical
|
||||
)
|
||||
.focused(focused)
|
||||
.onAppear {
|
||||
if let cursorOffset {
|
||||
placeCursor(at: cursorOffset)
|
||||
}
|
||||
}
|
||||
.onChange(of: textSelection) { _, nextSelection in
|
||||
updateCursorOffset(from: nextSelection)
|
||||
}
|
||||
.onChange(of: cursorPlacement) { _, placement in
|
||||
guard let placement else { return }
|
||||
placeCursor(at: placement.offset)
|
||||
}
|
||||
}
|
||||
|
||||
private func placeCursor(at requestedOffset: Int) {
|
||||
let offset = min(max(requestedOffset, 0), text.count)
|
||||
let index = text.index(text.startIndex, offsetBy: offset)
|
||||
textSelection = TextSelection(insertionPoint: index)
|
||||
cursorOffset = offset
|
||||
}
|
||||
|
||||
private func updateCursorOffset(from selection: TextSelection?) {
|
||||
guard let selection else {
|
||||
cursorOffset = nil
|
||||
return
|
||||
}
|
||||
|
||||
let cursorIndex: String.Index
|
||||
switch selection.indices {
|
||||
case let .selection(range):
|
||||
cursorIndex = range.upperBound
|
||||
case let .multiSelection(ranges):
|
||||
cursorIndex = ranges.ranges.last?.upperBound ?? text.endIndex
|
||||
@unknown default:
|
||||
cursorIndex = text.endIndex
|
||||
}
|
||||
cursorOffset = text.distance(from: text.startIndex, to: cursorIndex)
|
||||
}
|
||||
}
|
||||
|
||||
private struct FeatureComposerPathSearchRequest: Hashable {
|
||||
let scopeID: String
|
||||
let query: String
|
||||
|
||||
@@ -345,7 +345,7 @@ public struct ThreadDetailView: View {
|
||||
Task { await model.resolveUserInput(id, answers: answers) }
|
||||
}
|
||||
)
|
||||
.highPriorityGesture(composerKeyboardDismissGesture)
|
||||
.simultaneousGesture(composerKeyboardDismissGesture)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,23 +87,28 @@ public struct ProviderModelPicker: View {
|
||||
}
|
||||
|
||||
private var selectedOption: DailyUXModelOption? {
|
||||
guard let selection,
|
||||
let provider = providers.first(where: { $0.id == selection.providerID }),
|
||||
let model = provider.models.first(where: { $0.id == selection.modelID }) else {
|
||||
guard let resolvedSelection,
|
||||
let provider = providers.first(where: { $0.id == resolvedSelection.providerID }),
|
||||
let model = provider.models.first(where: { $0.id == resolvedSelection.modelID }) else {
|
||||
return nil
|
||||
}
|
||||
return DailyUXModelOption(provider: provider, model: model)
|
||||
}
|
||||
|
||||
private var resolvedSelection: FeatureSelection? {
|
||||
DailyUXModelOptions.validated(selection, in: providers)
|
||||
?? DailyUXModelOptions.preferredSelection(in: providers)
|
||||
}
|
||||
|
||||
private var selectionLabel: String {
|
||||
guard let selectedOption else {
|
||||
return selection == nil ? "Automatic" : "Model unavailable"
|
||||
return "Choose model"
|
||||
}
|
||||
let base = "\(selectedOption.provider.name) · \(selectedOption.model.name)"
|
||||
guard let selection,
|
||||
guard let resolvedSelection,
|
||||
let summary = DailyUXModelOptions.summary(
|
||||
for: selectedOption.model,
|
||||
selections: selection.options
|
||||
selections: resolvedSelection.options
|
||||
) else {
|
||||
return base
|
||||
}
|
||||
@@ -112,16 +117,16 @@ public struct ProviderModelPicker: View {
|
||||
|
||||
private var compactModelName: String {
|
||||
guard let selectedOption else {
|
||||
return selection == nil ? "Automatic" : "Choose model"
|
||||
return "Choose model"
|
||||
}
|
||||
return selectedOption.model.name
|
||||
}
|
||||
|
||||
private var compactReasoningLabel: String? {
|
||||
guard let selectedOption, let selection else { return nil }
|
||||
guard let selectedOption, let resolvedSelection else { return nil }
|
||||
return DailyUXModelOptions.reasoningSummary(
|
||||
for: selectedOption.model,
|
||||
selections: selection.options
|
||||
selections: resolvedSelection.options
|
||||
)
|
||||
}
|
||||
|
||||
@@ -135,7 +140,7 @@ public struct ProviderModelPicker: View {
|
||||
size: size
|
||||
)
|
||||
} else {
|
||||
Image(systemName: selection == nil ? "wand.and.stars" : "cpu")
|
||||
Image(systemName: "cpu")
|
||||
.font(.system(size: size * 0.72, weight: .semibold))
|
||||
.foregroundStyle(T3Colors.textSecondary)
|
||||
.frame(width: size, height: size)
|
||||
@@ -204,20 +209,6 @@ private struct ModelPickerSheet: View {
|
||||
|
||||
private var modelList: some View {
|
||||
List {
|
||||
if query.isEmpty {
|
||||
Section {
|
||||
Button {
|
||||
selection = nil
|
||||
dismiss()
|
||||
} label: {
|
||||
ModelAutomaticRow(isSelected: selection == nil)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(modelChangesAreLocked)
|
||||
.opacity(modelChangesAreLocked ? 0.36 : 1)
|
||||
}
|
||||
}
|
||||
|
||||
if modelChangesAreLocked {
|
||||
Section {
|
||||
Label(
|
||||
@@ -278,8 +269,8 @@ private struct ModelPickerSheet: View {
|
||||
} label: {
|
||||
ModelOptionLabel(
|
||||
option: option,
|
||||
isSelected: selection?.providerID == option.provider.id
|
||||
&& selection?.modelID == option.model.id
|
||||
isSelected: resolvedSelection?.providerID == option.provider.id
|
||||
&& resolvedSelection?.modelID == option.model.id
|
||||
)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
@@ -324,6 +315,11 @@ private struct ModelPickerSheet: View {
|
||||
)
|
||||
}
|
||||
|
||||
private var resolvedSelection: FeatureSelection? {
|
||||
DailyUXModelOptions.validated(selection, in: providers)
|
||||
?? DailyUXModelOptions.preferredSelection(in: providers)
|
||||
}
|
||||
|
||||
private func select(_ option: DailyUXModelOption) {
|
||||
guard !isLocked(option) else { return }
|
||||
if option.model.options.isEmpty {
|
||||
@@ -491,33 +487,6 @@ private struct ModelConfigurationView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private struct ModelAutomaticRow: View {
|
||||
let isSelected: Bool
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "wand.and.stars")
|
||||
.foregroundStyle(T3Colors.textSecondary)
|
||||
.frame(width: 24)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Automatic")
|
||||
.font(T3Typography.homeTitle)
|
||||
.foregroundStyle(T3Colors.textPrimary)
|
||||
Text("Use the environment default")
|
||||
.font(T3Typography.supporting)
|
||||
.foregroundStyle(T3Colors.textSecondary)
|
||||
}
|
||||
Spacer()
|
||||
if isSelected {
|
||||
Image(systemName: "checkmark")
|
||||
.font(.subheadline.weight(.bold))
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
}
|
||||
|
||||
private struct ModelOptionLabel: View {
|
||||
let option: DailyUXModelOption
|
||||
let isSelected: Bool
|
||||
@@ -531,9 +500,6 @@ private struct ModelOptionLabel: View {
|
||||
.font(T3Typography.homeTitle)
|
||||
.foregroundStyle(T3Colors.textPrimary)
|
||||
.lineLimit(1)
|
||||
if option.model.supportsReasoning {
|
||||
capability("Reasoning", icon: "brain")
|
||||
}
|
||||
if option.model.supportsImages {
|
||||
capability("Images", icon: "photo")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user