iOS: refile from the editor !259

merged merged by cmc on 2026-10-11 09:24 UTC · krz/orgstar:issue-55 into main

3 files changed, +27 −3

Layout: unified · split

Sources/OrgstarMobile/EditorScreen.swift +25 −2
@@ -32,12 +32,13 @@ struct EditorScreen: View {
32 32
33 /// One sheet at a time: two presenters on this screen interfere. 33 /// One sheet at a time: two presenters on this screen interfere.
34 enum Sheet: Identifiable { 34 enum Sheet: Identifiable {
35 case palette, conflict, syncCopies, recovery 35 case palette, conflict, syncCopies, recovery, refile
36 case block(BlockEdit) 36 case block(BlockEdit)
37 37
38 var id: String { 38 var id: String {
39 switch self { 39 switch self {
40 case .palette: "palette" 40 case .palette: "palette"
41 case .refile: "refile"
41 case .conflict: "conflict" 42 case .conflict: "conflict"
42 case .syncCopies: "syncCopies" 43 case .syncCopies: "syncCopies"
43 case .recovery: "recovery" 44 case .recovery: "recovery"
@@ -105,6 +106,11 @@ struct EditorScreen: View {
105 case .conflict: ConflictSheet(session: session) 106 case .conflict: ConflictSheet(session: session)
106 case .syncCopies: SyncConflictSheet(session: session) { message = $0 } 107 case .syncCopies: SyncConflictSheet(session: session) { message = $0 }
107 case .recovery: RecoverySheet(session: session) { message = $0 } 108 case .recovery: RecoverySheet(session: session) { message = $0 }
109 case .refile:
110 RefileSheet(targets: workspace.refileTargets(openPath: session.path, document: session.document)) { target in
111 self.sheet = nil
112 if let target { refile(to: target) }
113 }
108 case .block(let edit): 114 case .block(let edit):
109 BlockEditSheet(edit: edit, theme: MobileTheme(model.theme)) { content in 115 BlockEditSheet(edit: edit, theme: MobileTheme(model.theme)) { content in
110 self.sheet = nil 116 self.sheet = nil
@@ -192,7 +198,9 @@ struct EditorScreen: View {
192 editor.onRefreshSetup = { session.refreshSetup() } 198 editor.onRefreshSetup = { session.refreshSetup() }
193 editor.onAgenda = { start, count in model.agendaRequest = .init(start: start, count: count) } 199 editor.onAgenda = { start, count in model.agendaRequest = .init(start: start, count: count) }
194 editor.onAppCommand = { id in 200 editor.onAppCommand = { id in
195 if id == "app.toggle-markup" { 201 if id == "app.refile" {
202 sheet = .refile
203 } else if id == "app.toggle-markup" {
196 model.showMarkup.toggle() 204 model.showMarkup.toggle()
197 } else if MobileEditor.linkCommands.contains(id) { 205 } else if MobileEditor.linkCommands.contains(id) {
198 link(id) 206 link(id)
@@ -212,6 +220,20 @@ struct EditorScreen: View {
212 } 220 }
213} 221}
214 222
223extension EditorScreen {
224 /// `org-refile` of the entry at the caret, to a target worked out again from the files
225 /// now, as the agenda's Refile… does.
226 func refile(to target: RefileTarget) {
227 guard let editor, let path = session.path else { return }
228 let caret = editor.editContext().caret
229 guard let current = workspace.refileTargets(openPath: path, document: session.document).first(where: { $0.label == target.label }) else {
230 message = "Can't find \(target.label) any more."
231 return
232 }
233 message = session.refile(to: current, from: (path, caret))
234 }
235}
236
215/// The editor's text view, with the Org key bar over the keyboard. 237/// The editor's text view, with the Org key bar over the keyboard.
216struct EditorTextView: UIViewRepresentable { 238struct EditorTextView: UIViewRepresentable {
217 let editor: MobileEditor 239 let editor: MobileEditor
@@ -486,6 +508,7 @@ struct CommandPalette: View {
486 ("app.clock.goto", "Go to Clocked Entry"), ("app.clock.in-recent", "Clock In to Recent Entry…"), 508 ("app.clock.goto", "Go to Clocked Entry"), ("app.clock.in-recent", "Clock In to Recent Entry…"),
487 ("app.clock.in-last", "Clock In to Last Entry"), ("app.clock.goto-recent", "Go to Recent Clocked Entry…"), 509 ("app.clock.in-last", "Clock In to Last Entry"), ("app.clock.goto-recent", "Go to Recent Clocked Entry…"),
488 ("app.clock.default", "Mark as Default Clock Task"), ("app.clock.resolve", "Resolve Open Clocks…"), 510 ("app.clock.default", "Mark as Default Clock Task"), ("app.clock.resolve", "Resolve Open Clocks…"),
511 ("app.refile", "Refile…"),
489 ("app.toggle-markup", "Show or Hide Markup"), 512 ("app.toggle-markup", "Show or Hide Markup"),
490 ("org.toggle-inline-images", "Show or Hide Inline Images"), ("editor.toggle-truncate-lines", "Truncate or Wrap Long Lines"), 513 ("org.toggle-inline-images", "Show or Hide Inline Images"), ("editor.toggle-truncate-lines", "Truncate or Wrap Long Lines"),
491 ("org.table.toggle-column-width", "Shrink or Expand Table Column"), ("org.table.shrink", "Shrink Table Columns with Widths"), 514 ("org.table.toggle-column-width", "Shrink or Expand Table Column"), ("org.table.shrink", "Shrink Table Columns with Widths"),
Sources/OrgstarMobile/MobileEditor.swift +1
@@ -269,6 +269,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
269 case "org.cycle-global", "edit.undo", "edit.redo", "org.toggle-inline-images", "editor.toggle-truncate-lines": return true 269 case "org.cycle-global", "edit.undo", "edit.redo", "org.toggle-inline-images", "editor.toggle-truncate-lines": return true
270 case "app.clock.in", "app.clock.out", "app.clock.cancel", "app.clock.goto", "app.clock.in-recent", "app.clock.in-last", 270 case "app.clock.in", "app.clock.out", "app.clock.cancel", "app.clock.goto", "app.clock.in-recent", "app.clock.in-last",
271 "app.clock.goto-recent", "app.clock.default", "app.clock.resolve", "app.toggle-markup": return onAppCommand != nil 271 "app.clock.goto-recent", "app.clock.default", "app.clock.resolve", "app.toggle-markup": return onAppCommand != nil
272 case "app.refile": return onAppCommand != nil && Presentation.heading(containing: context.caret, in: context.tree) != nil
272 case _ where Self.linkCommands.contains(id): return onAppCommand != nil 273 case _ where Self.linkCommands.contains(id): return onAppCommand != nil
273 case "org.link.open": return OpenLinkAtPoint().applies(in: context) 274 case "org.link.open": return OpenLinkAtPoint().applies(in: context)
274 case "org.table.toggle-column-width", "org.table.shrink", "org.table.expand": 275 case "org.table.toggle-column-width", "org.table.shrink", "org.table.expand":
docs/manual/guide/14-ios.org +1 −1
@@ -376,4 +376,4 @@ Quick Look in the Files app shows org files as the HTML export renders them.
376- The global capture hotkey and the Settings window. 376- The global capture hotkey and the Settings window.
377- Explicit saving. 377- Explicit saving.
378 378
379Commands the iOS app can't carry out show a message instead, such as "Not available on iOS yet" or "/Command/ isn't available on iPhone and iPad." Only tables that need Emacs say that Emacs is needed. Commands that only appear on the Mac, such as Refile from the editor, aren't listed in Commands; refile and archive from the agenda instead. 379Commands the iOS app can't carry out show a message instead, such as "Not available on iOS yet" or "/Command/ isn't available on iPhone and iPad." Only tables that need Emacs say that Emacs is needed. Commands that only appear on the Mac aren't listed in Commands. Refile… in Commands (or =C-c C-w= with a hardware keyboard) refiles the entry at the caret, choosing the target as the agenda's Refile… does.