Skip to content

Commit

Permalink
Fix #3333: Clicking does not select in Assemblies pane when it doesn'…
Browse files Browse the repository at this point in the history
…t have focus
  • Loading branch information
tom-englert committed Nov 17, 2024
1 parent 09ed31d commit 446ce31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions ILSpy/AssemblyTree/AssemblyListPane.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using ICSharpCode.ILSpy.ViewModels;
using ICSharpCode.ILSpyX.TreeView;

using TomsToolbox.Wpf;
using TomsToolbox.Wpf.Composition.AttributedModel;

namespace ICSharpCode.ILSpy.AssemblyTree
Expand Down Expand Up @@ -56,7 +57,7 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
var selected = model.SelectedItem;
if (selected != null)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, () => {
this.BeginInvoke(DispatcherPriority.Background, () => {
ScrollIntoView(selected);
this.SelectedItem = selected;
});
Expand All @@ -69,7 +70,8 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)

if (SelectedItem is SharpTreeNode selectedItem)
{
FocusNode(selectedItem);
// defer focusing, so it does not interfere with selection via mouse click
this.BeginInvoke(() => FocusNode(selectedItem));
}
else
{
Expand Down
1 change: 1 addition & 0 deletions ILSpy/AssemblyTree/AssemblyTreeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ public void SelectNodes(IEnumerable<SharpTreeNode> nodes)
private void JumpToReference(object? sender, NavigateToReferenceEventArgs e)
{
JumpToReferenceAsync(e.Reference, e.InNewTabPage).HandleExceptions();
IsActive = true;
}

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions ILSpy/Controls/TreeView/SharpTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

using ICSharpCode.ILSpyX.TreeView;

using TomsToolbox.Wpf;

namespace ICSharpCode.ILSpy.Controls.TreeView
{
public class SharpTreeView : ListView
Expand Down Expand Up @@ -396,17 +398,18 @@ void ExpandRecursively(SharpTreeNode node)
/// </summary>
public void FocusNode(SharpTreeNode node)
{
if (node == null)
throw new ArgumentNullException("node");
ArgumentNullException.ThrowIfNull(node);

ScrollIntoView(node);

// WPF's ScrollIntoView() uses the same if/dispatcher construct, so we call OnFocusItem() after the item was brought into view.
if (this.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
{
OnFocusItem(node);
}
else
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(this.OnFocusItem), node);
this.BeginInvoke(DispatcherPriority.Loaded, () => OnFocusItem(node));
}
}

Expand Down

0 comments on commit 446ce31

Please sign in to comment.