Add show_page and show_file, and let file tools reach any path

This commit is contained in:
Ian Gulliver
2026-10-21 18:29:01 -07:00
parent 585c8ba5f8
commit 524bc0252e
11 changed files with 540 additions and 496 deletions
+30 -10
View File
@@ -22,21 +22,36 @@ extension Store {
func openFile(_ taskId: String, _ path: String) {
if isPage(path) {
route("#/task/\(taskId)")
openPage(.file(taskId: taskId, path: path))
showPage(taskId, path)
return
}
filePlaces[taskId] = path.hasSuffix("/") ? FilePlace(dir: String(path.dropLast())) : FilePlace(dir: parent(path), file: path)
showInFiles(taskId, path)
}
func showPage(_ taskId: String, _ path: String) {
route("#/task/\(taskId)")
openPage(.file(taskId: taskId, path: path))
}
func showInFiles(_ taskId: String, _ path: String) {
if path.isEmpty || path.hasSuffix("/") {
filePlaces[taskId] = FilePlace(dir: path == "/" ? path : String(path.dropLast()))
} else {
filePlaces[taskId] = FilePlace(dir: parent(path), file: path)
}
route("#/task/\(taskId)/files")
}
}
private func join(_ dir: String, _ name: String) -> String {
dir.isEmpty ? name : "\(dir)/\(name)"
dir.isEmpty ? name : dir.hasSuffix("/") ? "\(dir)\(name)" : "\(dir)/\(name)"
}
private func parent(_ path: String) -> String {
path.lastIndex(of: "/").map { String(path[..<$0]) } ?? ""
guard let i = path.lastIndex(of: "/") else {
return ""
}
return i == path.startIndex ? "/" : String(path[..<i])
}
private func bytes(_ n: Int64) -> String {
@@ -202,13 +217,18 @@ private struct FilesHead: View {
var body: some View {
let p = model.place
let path = p.file ?? p.dir
let parts = path.isEmpty ? [] : path.components(separatedBy: "/")
let absolute = path.hasPrefix("/")
let rest = absolute ? String(path.dropFirst()) : path
let parts = rest.isEmpty ? [] : rest.components(separatedBy: "/")
let base = absolute ? "/" : ""
HStack(alignment: .firstTextBaseline, spacing: 12) {
FlowLayout(spacing: 2) {
crumb("worktree", "", parts.isEmpty)
crumb(absolute ? "/" : "worktree", base, parts.isEmpty)
ForEach(Array(parts.enumerated()), id: \.offset) { i, part in
Text("/").foregroundStyle(Palette.muted)
crumb(part, parts[...i].joined(separator: "/"), i == parts.count - 1)
if !absolute || i > 0 {
Text("/").foregroundStyle(Palette.muted)
}
crumb(part, base + parts[...i].joined(separator: "/"), i == parts.count - 1)
}
}
Spacer(minLength: 0)
@@ -261,7 +281,7 @@ private struct FilesBody: View {
} else if let l = model.listing {
ScrollView {
VStack(alignment: .leading, spacing: 0) {
if !l.path.isEmpty {
if !l.path.isEmpty && l.path != "/" {
EntryRow(label: "../", kind: .dir, ignored: false, meta: "", symlink: false) {
model.go(FilePlace(dir: parent(l.path)))
}