krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

Commit 29fd24ba30

29fd24ba3077d4fac2a9eb592fb497157b333f4b

parent: f39ba0744e

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-09 05:35 UTC

iOS capture: use the shared scheduling helper

Capture onto an agenda day inserts SCHEDULED with Capture.scheduling, as the Mac does, which also joins an existing planning line. Filing uses the agenda day's time for placement (date tree, %U), as org-overriding-default-time does.

Layout: unified · split

Sources/OrgstarMobile/CaptureScreen.swift +2 −17
@@ -98,7 +98,7 @@ struct CaptureScreen: View {
9898 context.now = request.day.map(Self.date) ?? Date()
9999 switch Capture.fill(template.template, context: context, answers: answers) {
100100 case .success(let filled):
101 let (filledText, cursor) = request.day.map { Self.scheduling(filled.text, cursor: filled.cursor, on: $0) } ?? (filled.text, filled.cursor)
101 let (filledText, cursor) = request.day.map { Capture.scheduling(filled.text, cursor: filled.cursor, on: $0) } ?? (filled.text, filled.cursor)
102102 text = filledText
103103 selection = TextSelection(insertionPoint: String.Index(utf16Offset: cursor, in: filledText))
104104 problem = nil
@@ -120,26 +120,11 @@ struct CaptureScreen: View {
120120 return calendar.date(from: parts) ?? Date()
121121 }
122122
123 /// An entry captured from an agenda day is scheduled on it: a SCHEDULED line goes under
124 /// the heading unless the template already gave the entry an active timestamp. The caret
125 /// keeps its place in the text.
126 static func scheduling(_ text: String, cursor: Int, on day: Int) -> (String, Int) {
127 guard text.hasPrefix("*"), text.firstMatch(of: /<[0-9]{4}-[0-9]{2}-[0-9]{2}/) == nil else { return (text, cursor) }
128 let d = Days.date(day)
129 let weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][Days.weekday(day)]
130 let line = String(format: "SCHEDULED: <%04d-%02d-%02d ", d.year, d.month, d.day) + weekday + ">"
131 let utf16 = Array(text.utf16)
132 let end = utf16.firstIndex(of: 10) ?? utf16.count
133 let inserted = "\n" + line
134 let result = String(decoding: utf16[..<end], as: UTF16.self) + inserted + String(decoding: utf16[end...], as: UTF16.self)
135 return (result, cursor > end ? cursor + inserted.utf16.count : cursor)
136 }
137
138123 private func file() {
139124 guard let template else { return }
140125 let now = Date()
141126 let placed = template.resolved(workspace: workspace, session: session, clock: clock).flatMap { resolved in
142 session.capture(text, template: resolved.template, root: workspace.rootPaths.first, file: resolved.file, now: now)
127 session.capture(text, template: resolved.template, root: workspace.rootPaths.first, file: resolved.file, now: request.day.map(Self.date) ?? now)
143128 }
144129 switch placed {
145130 case .failure(let error):