Skip to content

Commit 2682dcb

Browse files
author
tom-englert
committed
Fix navigation history also for keyboard
1 parent b4a44f8 commit 2682dcb

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

ILSpy/AssemblyTree/AssemblyTreeModel.cs

+17-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
using ICSharpCode.Decompiler.Documentation;
4545
using ICSharpCode.Decompiler.TypeSystem.Implementation;
4646
using System.Reflection.Metadata;
47+
using System.Text;
48+
using System.Windows.Navigation;
4749

4850
using ICSharpCode.ILSpy.AppEnv;
4951
using ICSharpCode.ILSpy.Search;
5052
using ICSharpCode.Decompiler;
51-
using System.Text;
5253

5354
using TomsToolbox.Essentials;
5455
using TomsToolbox.Wpf;
55-
using System.Windows.Navigation;
5656

5757
namespace ICSharpCode.ILSpy.AssemblyTree
5858
{
@@ -78,7 +78,7 @@ public AssemblyTreeModel()
7878
MessageBus<NavigateToReferenceEventArgs>.Subscribers += JumpToReference;
7979
MessageBus<SettingsChangedEventArgs>.Subscribers += (sender, e) => Settings_PropertyChanged(sender, e);
8080

81-
var selectionChangeThrottle = new DispatcherThrottle(DispatcherPriority.Background, TreeView_SelectionChanged);
81+
var selectionChangeThrottle = new DispatcherThrottle(DispatcherPriority.Input, TreeView_SelectionChanged);
8282
SelectedItems.CollectionChanged += (_, _) => selectionChangeThrottle.Tick();
8383
}
8484

@@ -128,6 +128,14 @@ public SharpTreeNode SelectedItem {
128128

129129
public ObservableCollection<SharpTreeNode> SelectedItems { get; } = [];
130130

131+
private bool isInternalSelectionChanging;
132+
133+
private void ChangingSelection()
134+
{
135+
isInternalSelectionChanging = true;
136+
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, () => isInternalSelectionChanging = false);
137+
}
138+
131139
public string[] SelectedPath => GetPathForNode(SelectedItem);
132140

133141
readonly List<LoadedAssembly> commandLineLoadedAssemblies = [];
@@ -496,6 +504,7 @@ public void SelectNode(SharpTreeNode node, bool inNewTabPage = false)
496504
}
497505
else
498506
{
507+
ChangingSelection();
499508
activeView?.ScrollIntoView(node);
500509
SelectedItem = node;
501510
}
@@ -519,6 +528,7 @@ internal void SelectNodes(IEnumerable<SharpTreeNode> nodes)
519528
return;
520529
}
521530

531+
ChangingSelection();
522532
SelectedItems.Clear();
523533
SelectedItems.AddRange(nodesList);
524534
}
@@ -691,20 +701,17 @@ void TreeView_SelectionChanged()
691701
{
692702
if (SelectedItems.Count > 0)
693703
{
694-
bool isRightButtonPressed = Mouse.RightButton == MouseButtonState.Pressed;
695-
bool isLeftButtonPressed = Mouse.LeftButton == MouseButtonState.Pressed;
696-
697-
if (isLeftButtonPressed || isRightButtonPressed)
704+
if (!isInternalSelectionChanging)
698705
{
699-
// record history only if change is initiated by user
706+
// record history only if change is initiated by user input
700707
var activeTabPage = DockWorkspace.Instance.ActiveTabPage;
701708
var currentState = activeTabPage.GetState();
702709
if (currentState != null)
703710
history.UpdateCurrent(new NavigationState(activeTabPage, currentState));
704711
history.Record(new NavigationState(activeTabPage, SelectedItems));
705712
}
706713

707-
var delayDecompilationRequestDueToContextMenu = isRightButtonPressed;
714+
var delayDecompilationRequestDueToContextMenu = Mouse.RightButton == MouseButtonState.Pressed;
708715

709716
if (!delayDecompilationRequestDueToContextMenu)
710717
{
@@ -855,6 +862,7 @@ public void Refresh()
855862

856863
private void UnselectAll()
857864
{
865+
ChangingSelection();
858866
SelectedItems.Clear();
859867
}
860868

ILSpy/MainWindow.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
<Window.InputBindings>
3939
<KeyBinding Key="R" Modifiers="Control" Command="{x:Static local:ILSpyCommands.Analyze}" />
40+
<KeyBinding Key="Z" Modifiers="Control" Command="{x:Static NavigationCommands.BrowseBack}" />
4041
</Window.InputBindings>
4142

4243
<Window.TaskbarItemInfo>

0 commit comments

Comments
 (0)