import SwiftUI /// Edit one file and commit it. The commit is unsigned — the server /// authors it — so a repository requiring signatures refuses, and the /// refusal is what the sheet shows. struct FileEditSheet: View { let model: FileViewModel let branch: String @Binding var content: String let onCommitted: () -> Void @Environment(\.dismiss) private var dismiss @State private var message = "" var body: some View { NavigationStack { Form { Section { TextEditor(text: $content) .font(.gbMono(.caption)) .frame(minHeight: 260) .autocorrectionDisabled() .textInputAutocapitalization(.never) .accessibilityIdentifier("file-edit-content") } header: { Text(model.fileName) } footer: { Text("Commits to \(branch) as an unsigned commit.") } Section("Message") { TextField("edit \(model.fileName)", text: $message) .autocorrectionDisabled() .accessibilityIdentifier("file-edit-message") } if let error = model.actionError { Section { GBNotice(error, .gbWarn) } } } .navigationTitle("Edit") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel") { dismiss() } } ToolbarItem(placement: .confirmationAction) { if model.working { ProgressView() } else { Button("Commit") { Task { if await model.commit(content: content, message: message) { onCommitted() } } } .accessibilityIdentifier("file-edit-commit") } } } .interactiveDismissDisabled(model.working) } } }