Commit 3ae217cf9d

3ae217cf9d3d7884e3e5238934298e929bcc5cc0

parent: 63ae15b64d

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-26 18:20 UTC

iOS passphrase sheet: navigation bar buttons and a form

Layout: unified · split

Sources/OrgApp/CryptSheet.swift +57 −5 · view
@@ -84,7 +84,8 @@ public struct CryptSheet: View {
84 self.done = done 84 self.done = done
85 } 85 }
86 86
87 public var body: some View { 87 #if os(macOS)
88 private var layout: some View {
88 VStack(alignment: .leading, spacing: 12) { 89 VStack(alignment: .leading, spacing: 12) {
89 if editing != nil { 90 if editing != nil {
90 Text("Encrypted Entry").font(.headline) 91 Text("Encrypted Entry").font(.headline)
@@ -114,11 +115,62 @@ public struct CryptSheet: View {
114 } 115 }
115 } 116 }
116 .padding(20) 117 .padding(20)
117 #if os(macOS)
118 .frame(minWidth: 460) 118 .frame(minWidth: 460)
119 #else 119 }
120 .frame(maxHeight: .infinity, alignment: .top) 120 #else
121 #endif 121 @FocusState private var fieldFocused: Bool
122
123 /// The editor's sheet: a navigation bar with Cancel and the action, the fields in a form.
124 private var layout: some View {
125 Form {
126 if editing != nil {
127 Section {
128 TextEditor(text: $plaintext)
129 .font(.body.monospaced())
130 .frame(minHeight: 220)
131 } footer: {
132 if let problem { Text(problem).foregroundStyle(.red) }
133 }
134 Section {
135 Button("Decrypt in File") { decryptEdited() }
136 }
137 } else {
138 Section {
139 SecureField("Passphrase", text: $passphrase)
140 .focused($fieldFocused)
141 .submitLabel(.go)
142 .onSubmit(submit)
143 if asksTwice { SecureField("Repeat passphrase", text: $repeated).submitLabel(.go).onSubmit(submit) }
144 } footer: {
145 VStack(alignment: .leading, spacing: 6) {
146 if let explanation { Text(explanation) }
147 if let problem { Text(problem).foregroundStyle(.red) }
148 }
149 }
150 }
151 }
152 .navigationTitle(editing != nil ? String(localized: "Encrypted Entry") : title)
153 .toolbar {
154 ToolbarItem(placement: .cancellationAction) {
155 Button("Cancel", role: .cancel) { if editing != nil { done(nil) } else { cancel() } }
156 }
157 ToolbarItem(placement: .confirmationAction) {
158 if editing != nil {
159 Button("Save") { save() }
160 } else {
161 Button(request.encrypting ? "Encrypt" : "Decrypt") { submit() }.disabled(passphrase.isEmpty)
162 }
163 }
164 }
165 .presentationDetents(editing != nil ? [.large] : [.medium, .large])
166 .onAppear { fieldFocused = true }
167 // A wrong passphrase: the field again, to type it over.
168 .onChange(of: problem) { if problem != nil, editing == nil { fieldFocused = true } }
169 }
170 #endif
171
172 public var body: some View {
173 layout
122 .task { 174 .task {
123 if let stored = await passphrases.stored(for: request.path) { run(stored, remembered: true) } 175 if let stored = await passphrases.stored(for: request.path) { run(stored, remembered: true) }
124 } 176 }
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form