Skip to content

Commit 446ce31

Browse files
committed
Fix #3333: Clicking does not select in Assemblies pane when it doesn't have focus
1 parent 09ed31d commit 446ce31

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

ILSpy/AssemblyTree/AssemblyListPane.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using ICSharpCode.ILSpy.ViewModels;
2424
using ICSharpCode.ILSpyX.TreeView;
2525

26+
using TomsToolbox.Wpf;
2627
using TomsToolbox.Wpf.Composition.AttributedModel;
2728

2829
namespace ICSharpCode.ILSpy.AssemblyTree
@@ -56,7 +57,7 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
5657
var selected = model.SelectedItem;
5758
if (selected != null)
5859
{
59-
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, () => {
60+
this.BeginInvoke(DispatcherPriority.Background, () => {
6061
ScrollIntoView(selected);
6162
this.SelectedItem = selected;
6263
});
@@ -69,7 +70,8 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
6970

7071
if (SelectedItem is SharpTreeNode selectedItem)
7172
{
72-
FocusNode(selectedItem);
73+
// defer focusing, so it does not interfere with selection via mouse click
74+
this.BeginInvoke(() => FocusNode(selectedItem));
7375
}
7476
else
7577
{

ILSpy/AssemblyTree/AssemblyTreeModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ public void SelectNodes(IEnumerable<SharpTreeNode> nodes)
640640
private void JumpToReference(object? sender, NavigateToReferenceEventArgs e)
641641
{
642642
JumpToReferenceAsync(e.Reference, e.InNewTabPage).HandleExceptions();
643+
IsActive = true;
643644
}
644645

645646
/// <summary>

ILSpy/Controls/TreeView/SharpTreeView.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
using ICSharpCode.ILSpyX.TreeView;
3232

33+
using TomsToolbox.Wpf;
34+
3335
namespace ICSharpCode.ILSpy.Controls.TreeView
3436
{
3537
public class SharpTreeView : ListView
@@ -396,17 +398,18 @@ void ExpandRecursively(SharpTreeNode node)
396398
/// </summary>
397399
public void FocusNode(SharpTreeNode node)
398400
{
399-
if (node == null)
400-
throw new ArgumentNullException("node");
401+
ArgumentNullException.ThrowIfNull(node);
402+
401403
ScrollIntoView(node);
404+
402405
// WPF's ScrollIntoView() uses the same if/dispatcher construct, so we call OnFocusItem() after the item was brought into view.
403406
if (this.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
404407
{
405408
OnFocusItem(node);
406409
}
407410
else
408411
{
409-
this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(this.OnFocusItem), node);
412+
this.BeginInvoke(DispatcherPriority.Loaded, () => OnFocusItem(node));
410413
}
411414
}
412415

0 commit comments

Comments
 (0)