Commit d85099bc95

d85099bc95bf1766aee990d94671dacda0c0686e

parent: a6d26284f0

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-11 11:54 UTC

Column view on iOS

Adds ColumnViewScreen, opened from the editor's More menu (Column View, Column View of File) and from org.columns in Commands: the grid with summaries, cell selection, Edit with allowed values, previous and next value, and Go to Entry.

Closes #28

Layout: unified · split

Sources/OrgstarMobile/ColumnViewScreen.swift added +136
@@ -0,0 +1,136 @@
1#if os(iOS)
2import OrgApp
3import OrgCore
4import SwiftUI
5
6/// `org-columns` on iOS: the entries and their columns, with summaries, as on the Mac. Tap a
7/// cell to select it; the bar edits it (`e`), moves to the previous or next allowed value
8/// (`p`, `n`), or goes to the entry.
9struct ColumnViewScreen: View {
10 @State var view: ColumnView.View
11 let session: DocumentSession
12 let path: String
13 let jump: (Int) -> Void
14 @Environment(\.dismiss) private var dismiss
15 @State private var selected: (row: Int, column: Int)?
16 @State private var message: String?
17 @State private var prompt: EditorScreen.PromptRequest?
18
19 var body: some View {
20 NavigationStack {
21 ScrollView([.horizontal, .vertical]) {
22 Grid(alignment: .leading, horizontalSpacing: 14, verticalSpacing: 6) {
23 GridRow {
24 ForEach(view.specs.indices, id: \.self) { i in
25 Text(view.specs[i].title).bold().foregroundStyle(.secondary)
26 }
27 }
28 Divider()
29 ForEach(view.rows.indices, id: \.self) { r in
30 GridRow {
31 ForEach(view.specs.indices, id: \.self) { c in cellView(r, c) }
32 }
33 }
34 }
35 .font(.system(.callout, design: .monospaced))
36 .padding(12)
37 }
38 .defaultScrollAnchor(.topLeading)
39 .navigationTitle("Column View")
40 .navigationBarTitleDisplayMode(.inline)
41 .toolbar {
42 ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } }
43 ToolbarItemGroup(placement: .bottomBar) {
44 Button("Edit", systemImage: "pencil") { edit() }.disabled(selected == nil)
45 Button("Previous Value", systemImage: "chevron.up") { cycle(previous: true) }.disabled(selected == nil)
46 Button("Next Value", systemImage: "chevron.down") { cycle(previous: false) }.disabled(selected == nil)
47 Spacer()
48 Button("Go to Entry", systemImage: "arrow.right.doc.on.clipboard") {
49 guard let selected else { return }
50 jump(view.rows[selected.row].start)
51 dismiss()
52 }
53 .disabled(selected == nil)
54 }
55 }
56 .safeAreaInset(edge: .top) {
57 if let message {
58 Text(message).font(.footnote).padding(.horizontal, 12).padding(.vertical, 6)
59 .glassEffect(.regular, in: Capsule())
60 .onTapGesture { self.message = nil }
61 }
62 }
63 .sheet(item: $prompt) { request in
64 PromptSheet(prompt: request.prompt) { answer in
65 prompt = nil
66 request.reply(answer)
67 }
68 }
69 }
70 }
71
72 private func cellView(_ r: Int, _ c: Int) -> some View {
73 let row = view.rows[r]
74 let isSelected = selected.map { $0 == (r, c) } ?? false
75 let text = view.specs[c].property == "ITEM" ? String(repeating: "*", count: row.level) + " " + row.values[c] : row.values[c]
76 return Text(text.isEmpty ? " " : text)
77 .lineLimit(1)
78 .frame(maxWidth: view.specs[c].width.map { CGFloat($0) * 8.5 }, alignment: .leading)
79 .padding(.horizontal, 3)
80 .padding(.vertical, 2)
81 .background(isSelected ? Color.accentColor.opacity(0.25) : .clear, in: RoundedRectangle(cornerRadius: 4))
82 .contentShape(Rectangle())
83 .onTapGesture { selected = (r, c) }
84 .accessibilityAddTraits(isSelected ? [.isButton, .isSelected] : .isButton)
85 .accessibilityAction(named: "Edit") {
86 selected = (r, c)
87 edit()
88 }
89 }
90
91 /// `org-columns-edit-value`: asks for the value, offering the allowed ones.
92 private func edit() {
93 guard let (r, c) = selected else { return }
94 let spec = view.specs[c]
95 let row = view.rows[r]
96 if ["CLOCKSUM", "CLOCKSUM_T", "ALLTAGS", "BLOCKED", "CLOSED", "FILE", "TIMESTAMP", "TIMESTAMP_IA"].contains(spec.property) {
97 message = "This special column cannot be edited"
98 return
99 }
100 let allowed = session.document.flatMap { PropertyValues.allowed(spec.property, at: row.start, text: $0.text, tree: $0.tree)?.values } ?? []
101 let initial = row.raw.indices.contains(c) ? row.raw[c] : row.values[c]
102 // With allowed values the field starts empty, so that they all show.
103 let message = allowed.isEmpty || initial.isEmpty ? spec.title : "\(spec.title) (now \(initial))"
104 prompt = EditorScreen.PromptRequest(prompt: Prompt(key: "value", message: message, initial: allowed.isEmpty ? initial : "", choices: allowed)) { answer in
105 guard let answer else { return }
106 perform(SetColumnValue(property: spec.property, value: answer), at: row.start)
107 }
108 }
109
110 private func cycle(previous: Bool) {
111 guard let (r, c) = selected else { return }
112 let spec = view.specs[c]
113 perform(NextColumnValue(property: spec.property, summary: spec.summary, previous: previous), at: view.rows[r].start)
114 }
115
116 private func perform(_ command: any OrgCommand, at start: Int, answers: [String: String] = [:]) {
117 switch session.perform(command, path: path, at: start, expect: nil, answers: answers) {
118 case .commit:
119 message = nil
120 guard let document = session.document, let new = try? ColumnView.refresh(view, text: document.text, tree: document.tree) else { return }
121 view = new
122 if let selected, selected.row >= new.rows.count { self.selected = nil }
123 case .failed(let text):
124 message = text
125 case .prompt(let request):
126 // A state note, or what else the change asks.
127 prompt = EditorScreen.PromptRequest(prompt: request) { answer in
128 guard let answer else { return }
129 perform(command, at: start, answers: answers.merging([request.key: answer]) { $1 })
130 }
131 case .external(let request):
132 message = MobileEditor.unavailable(request, title: command.title)
133 }
134 }
135}
136#endif
Sources/OrgstarMobile/EditorScreen.swift +7
@@ -44,6 +44,7 @@ struct EditorScreen: View {
4444 /// `app.refile`, `app.refile.copy` or `app.refile.goto`.
4545 case refile(String)
4646 case block(BlockEdit)
47 case columns(ColumnView.View)
4748
4849 var id: String {
4950 switch self {
@@ -53,6 +54,7 @@ struct EditorScreen: View {
5354 case .syncCopies: "syncCopies"
5455 case .recovery: "recovery"
5556 case .block(let edit): "block \(edit.range)"
57 case .columns: "columns"
5658 }
5759 }
5860 }
@@ -78,6 +80,8 @@ struct EditorScreen: View {
7880 Menu("More", systemImage: "ellipsis.circle") {
7981 Button("Commands", systemImage: "command") { sheet = .palette }
8082 Button("Clock In", systemImage: "stopwatch") { editor?.run("app.clock.in") }
83 Button("Column View", systemImage: "tablecells") { editor?.run("org.columns") }
84 Button("Column View of File", systemImage: "tablecells.badge.ellipsis") { editor?.run("org.columns.global") }
8185 Toggle(isOn: Binding(get: { model.showMarkup }, set: { model.showMarkup = $0 })) {
8286 Label("Show Markup", systemImage: "chevron.left.forwardslash.chevron.right")
8387 }
@@ -140,6 +144,8 @@ struct EditorScreen: View {
140144 self.sheet = nil
141145 if let content, let editor { _ = editor.perform(ReplaceBlockLines(edit: edit, content: content)) }
142146 }
147 case .columns(let view):
148 ColumnViewScreen(view: view, session: session, path: path) { offset in editor?.reveal(offset) }
143149 }
144150 }
145151 .onChange(of: session.conflict) { _, conflict in
@@ -219,6 +225,7 @@ struct EditorScreen: View {
219225 }
220226 }
221227 editor.onEditBlock = { edit in sheet = .block(edit) }
228 editor.onColumnView = { view in sheet = .columns(view) }
222229 editor.onTangle = { scope in message = session.tangle(scope) }
223230 editor.onBabel = { job in run(job) }
224231 editor.onRefreshSetup = { session.refreshSetup() }
Sources/OrgstarMobile/MobileEditor.swift +4
@@ -82,6 +82,8 @@ final class MobileEditor: NSObject, DocumentBuffer {
8282 var onEditBlock: ((BlockEdit) -> Void)?
8383 /// A followed timestamp's agenda days: the first (a `Days` number) and how many.
8484 var onAgenda: ((Int, Int) -> Void)?
85 /// Shows a column view.
86 var onColumnView: ((ColumnView.View) -> Void)?
8587 /// Commands the app runs, as `app.clock.in`.
8688 var onAppCommand: ((String) -> Void)?
8789 /// Tags used across the workspace, for completion.
@@ -233,6 +235,8 @@ final class MobileEditor: NSObject, DocumentBuffer {
233235 onTangle?(scope)
234236 case .external(.agenda(let start, let count)) where onAgenda != nil:
235237 onAgenda?(start, count)
238 case .external(.columnView(let view)) where onColumnView != nil:
239 onColumnView?(view)
236240 case .external(let request):
237241 onMessage?(Self.unavailable(request, title: command.title))
238242 }
docs/manual/guide/04-outlines.org +5
@@ -678,6 +678,11 @@ The allowed values are the property's =_ALL= values from the entry, an ancestor
678678earlier; Org 9.8.7 signals an error there instead. After each change the sheet captures
679679the view again, so summaries follow. Parent summaries are not written into the file.
680680
681On iOS, choose Column View or Column View of File from the editor's More menu. The view
682scrolls both ways; tap a cell to select it. The bar at the bottom has Edit, which asks
683for the value with the allowed values listed, Previous Value and Next Value (=p= and
684=n=), and Go to Entry. Done closes it.
685
681686** The Columns inspector
682687
683688View ▸ Show or Hide Columns and Clock opens an inspector beside the editor. Its Columns
docs/manual/guide/14-ios.org +1 −1
@@ -371,7 +371,7 @@ Quick Look in the Files app shows org files as the HTML export renders them.
371371- Word, ODT, LaTeX, ASCII and LaTeX-made PDF export.
372372- Idle detection while a clock runs.
373373- Import from Emacs.
374- The board, column view, the backlinks pane, and the buffer list and tab bar.
374- The Columns inspector, the backlinks pane, and the buffer list and tab bar. The board and column view are there (see [[file:07-agenda.org][The agenda]] and [[file:04-outlines.org][Outlines]]).
375375- The global capture hotkey and the Settings window.
376376- Explicit saving.
377377