fix(workspace): make file rows deterministic
This commit is contained in:
parent
a0ca8bf89c
commit
4d7a0d04c2
1 changed files with 27 additions and 8 deletions
|
|
@ -34,7 +34,7 @@ public struct WorkspaceTreeView: View {
|
||||||
if let workspace {
|
if let workspace {
|
||||||
List(selection: $selection) {
|
List(selection: $selection) {
|
||||||
Section(workspace.name) {
|
Section(workspace.name) {
|
||||||
ForEach(workspace.items) { item in
|
ForEach(workspace.items, id: \.stableTreeID) { item in
|
||||||
WorkspaceItemRow(
|
WorkspaceItemRow(
|
||||||
item: item,
|
item: item,
|
||||||
selection: $selection,
|
selection: $selection,
|
||||||
|
|
@ -69,7 +69,7 @@ private struct WorkspaceItemRow: View {
|
||||||
switch item {
|
switch item {
|
||||||
case .folder(let folder):
|
case .folder(let folder):
|
||||||
DisclosureGroup {
|
DisclosureGroup {
|
||||||
ForEach(folder.children) { child in
|
ForEach(folder.children, id: \.stableTreeID) { child in
|
||||||
WorkspaceItemRow(
|
WorkspaceItemRow(
|
||||||
item: child,
|
item: child,
|
||||||
selection: $selection,
|
selection: $selection,
|
||||||
|
|
@ -86,17 +86,21 @@ private struct WorkspaceItemRow: View {
|
||||||
}
|
}
|
||||||
.tag(WorkspaceTreeSelection.folder(folder.url))
|
.tag(WorkspaceTreeSelection.folder(folder.url))
|
||||||
case .file(let file):
|
case .file(let file):
|
||||||
Label(file.name, systemImage: iconName(for: file.kind))
|
Button {
|
||||||
.foregroundStyle(file.kind == .markdown ? .primary : .secondary)
|
if file.kind == .markdown {
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
selection = .file(file.url)
|
selection = .file(file.url)
|
||||||
onSelectFile(file)
|
onSelectFile(file)
|
||||||
}
|
}
|
||||||
|
} label: {
|
||||||
|
Label(file.name, systemImage: iconName(for: file.kind))
|
||||||
|
.foregroundStyle(file.kind == .markdown ? .primary : .secondary)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.disabled(file.kind != .markdown)
|
||||||
.tag(WorkspaceTreeSelection.file(file.url))
|
.tag(WorkspaceTreeSelection.file(file.url))
|
||||||
case .project(let project):
|
case .project(let project):
|
||||||
DisclosureGroup {
|
DisclosureGroup {
|
||||||
ForEach(project.children) { child in
|
ForEach(project.children, id: \.stableTreeID) { child in
|
||||||
WorkspaceItemRow(
|
WorkspaceItemRow(
|
||||||
item: child,
|
item: child,
|
||||||
selection: $selection,
|
selection: $selection,
|
||||||
|
|
@ -130,3 +134,18 @@ private struct WorkspaceItemRow: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension WorkspaceItem {
|
||||||
|
var stableTreeID: URL {
|
||||||
|
switch self {
|
||||||
|
case .folder(let folder):
|
||||||
|
return folder.url.standardizedFileURL
|
||||||
|
case .file(let file):
|
||||||
|
return file.url.standardizedFileURL
|
||||||
|
case .project(let project):
|
||||||
|
return project.repositoryURL.standardizedFileURL
|
||||||
|
case .subproject(let subproject):
|
||||||
|
return subproject.repositoryURL.standardizedFileURL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue