Commit d93697b86a
Verified · cmc
Layout: unified · split
Sources/OrgApp/ClockModel.swift +11 −2
| @@ -347,8 +347,13 @@ public final class ClockModel { | ||
| 347 | 347 | |
| 348 | 348 | /// `org-find-open-clocks` over `paths` and the open org buffers. |
| 349 | 349 | 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 } | |
| 350 | 354 | 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 } | |
| 352 | 357 | var clocks: [OpenClock] = [] |
| 353 | 358 | for path in all { |
| 354 | 359 | guard let text = Self.text(path, session), text.contains("CLOCK: [") else { continue } |
| @@ -401,9 +406,13 @@ public final class ClockModel { | ||
| 401 | 406 | func resolve( |
| 402 | 407 | _ clock: OpenClock, description: String, lastValid: Date, clockingIn: Bool, _ session: DocumentSession, ask: Ask, now: () -> Date |
| 403 | 408 | ) 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 | } | |
| 404 | 414 | isResolving = true |
| 405 | 415 | defer { isResolving = false } |
| 406 | var outcome = Outcome() | |
| 407 | 416 | var key: Character = "q" |
| 408 | 417 | while true { |
| 409 | 418 | guard let answer = await ask(Prompt(key: "clock-resolve", message: description + ClockResolution.keyHint, fast: ClockResolution.menu)) else { |