From a8fb8cbcb6dac4744bdc408f7f9ee50a0c3d4aa7 Mon Sep 17 00:00:00 2001 From: Alistair Pullen Date: Tue, 2 Sep 2025 20:11:00 +0000 Subject: [PATCH] feat: add tag support to sidebar rows for improved scrolling and selection management Co-authored-by: Genie --- JSONViewer/UI/SidebarView.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/JSONViewer/UI/SidebarView.swift b/JSONViewer/UI/SidebarView.swift index 2e7c1d3..50b5517 100644 --- a/JSONViewer/UI/SidebarView.swift +++ b/JSONViewer/UI/SidebarView.swift @@ -76,6 +76,7 @@ struct SidebarView: View { ForEach(filtered, id: \.self) { i in SidebarRowView(viewModel: viewModel, id: i) .id(i) + .tag(i) .onAppear { if let last = filtered.last, i == last { isAtBottom = true } } @@ -87,6 +88,7 @@ struct SidebarView: View { ForEach(0.. 0 { + // Also move the selection to the new last row so the detail view matches what's shown at bottom. + viewModel.selectedRowID = newCount - 1 DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { withAnimation(.easeInOut(duration: 0.15)) { proxy.scrollTo(newCount - 1, anchor: .bottom) @@ -137,6 +141,7 @@ struct SidebarView: View { } .padding(.vertical, 4) .contentShape(Rectangle()) + .tag(row.id) .onAppear { if let last = filteredRows.last?.id, row.id == last { isAtBottom = true } }