Browse Source

Port #3705 — async wait for load before refresh path-walk

Cherry-picked from master commits 4c8e606a6 + 4c347ef6b. Refresh (F5) on a
selection inside a lazy-loaded resource tree (e.g. a .baml entry inside an
embedded .resources file) was collapsing the selection back to the resources
folder because FindNodeByPath ran before the assembly's metadata-file
finished loading and the resource children hadn't materialised yet.

Assisted-by: Claude:claude-opus-4-7:Claude Code
pull/3755/head
Siegfried Pammer 2 months ago
parent
commit
53db111cd6
  1. 26
      ILSpy/AssemblyTree/AssemblyTreeModel.cs

26
ILSpy/AssemblyTree/AssemblyTreeModel.cs

@ -728,14 +728,36 @@ namespace ILSpy.AssemblyTree @@ -728,14 +728,36 @@ namespace ILSpy.AssemblyTree
}
}
public void Refresh() => RefreshInternal();
public void Refresh() => _ = RefreshInternalAsync();
void RefreshInternal()
async Task RefreshInternalAsync()
{
if (AssemblyList == null || listManager == null)
return;
var path = GetPathForNode(SelectedItem);
ShowAssemblyList(listManager.LoadList(AssemblyList.ListName));
// Ensure the assembly's children are realised before FindNodeByPath walks them.
// Lazy-loaded resource children (e.g. .baml entries inside an embedded
// .resources file) only materialise after the assembly's metadata-file is
// loaded; without this await the path-walk runs against an empty resource
// folder and the selection collapses to the resources folder itself (#3705 in
// the WPF tree). If the user navigated to a different node while we waited,
// honour that new selection rather than overwriting it with the pre-refresh path.
if (path is { Length: > 0 })
{
var rootAssembly = AssemblyList.FindAssembly(path[0]);
if (rootAssembly != null)
{
var preAwaitSelection = SelectedItem;
try
{ await rootAssembly.GetMetadataFileAsync().ConfigureAwait(true); }
catch { /* corrupt assembly — let FindNodeByPath best-match below */ }
if (!ReferenceEquals(SelectedItem, preAwaitSelection))
return;
}
}
SelectNode(FindNodeByPath(path, returnBestMatch: true));
}
}

Loading…
Cancel
Save