krz/orgstar

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

Commit d93697b86a

d93697b86a2a713412a65792e11b89814b00f359

parent: 1569d791fb

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-08 07:45 UTC

Read open clocks from the buffer when a file is open under another path

A clock closed by an earlier answer is not asked about again.

Layout: unified · split

Sources/OrgApp/ClockModel.swift +11 −2
@@ -347,8 +347,13 @@ public final class ClockModel {
347347
348348 /// `org-find-open-clocks` over `paths` and the open org buffers.
349349 public func openClocks(_ session: DocumentSession, paths: [String]) -> [OpenClock] {
350 // A file open under another spelling of its path is read from its buffer.
351 func resolved(_ path: String) -> String { URL(fileURLWithPath: path).resolvingSymlinksInPath().path }
352 var open: [String: String] = [:]
353 for document in session.openDocuments { open[resolved(document.path)] = document.path }
350354 var seen = Set<String>()
351 let all = (paths + session.openDocuments.map(\.path).filter { $0.hasSuffix(".org") }).filter { seen.insert($0).inserted }
355 let all = (session.openDocuments.map(\.path).filter { $0.hasSuffix(".org") } + paths.map { open[resolved($0)] ?? $0 })
356 .filter { seen.insert(resolved($0)).inserted }
352357 var clocks: [OpenClock] = []
353358 for path in all {
354359 guard let text = Self.text(path, session), text.contains("CLOCK: [") else { continue }
@@ -401,9 +406,13 @@ public final class ClockModel {
401406 func resolve(
402407 _ clock: OpenClock, description: String, lastValid: Date, clockingIn: Bool, _ session: DocumentSession, ask: Ask, now: () -> Date
403408 ) async -> Outcome {
409 var outcome = Outcome()
410 // An earlier answer may have closed it.
411 guard let text = Self.text(clock.path, session), ClockResolution.openClocks(in: text).contains(where: { $0.start == clock.start }) else {
412 return outcome
413 }
404414 isResolving = true
405415 defer { isResolving = false }
406 var outcome = Outcome()
407416 var key: Character = "q"
408417 while true {
409418 guard let answer = await ask(Prompt(key: "clock-resolve", message: description + ClockResolution.keyHint, fast: ClockResolution.menu)) else {