Skip to content

Commit

Permalink
Fix navigation history also for keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Sep 22, 2024
1 parent b4a44f8 commit 2682dcb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
26 changes: 17 additions & 9 deletions ILSpy/AssemblyTree/AssemblyTreeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using System.Reflection.Metadata;
using System.Text;
using System.Windows.Navigation;

using ICSharpCode.ILSpy.AppEnv;
using ICSharpCode.ILSpy.Search;
using ICSharpCode.Decompiler;
using System.Text;

using TomsToolbox.Essentials;
using TomsToolbox.Wpf;
using System.Windows.Navigation;

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

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

Expand Down Expand Up @@ -128,6 +128,14 @@ public SharpTreeNode SelectedItem {

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

private bool isInternalSelectionChanging;

private void ChangingSelection()
{
isInternalSelectionChanging = true;
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, () => isInternalSelectionChanging = false);
}

public string[] SelectedPath => GetPathForNode(SelectedItem);

readonly List<LoadedAssembly> commandLineLoadedAssemblies = [];
Expand Down Expand Up @@ -496,6 +504,7 @@ public void SelectNode(SharpTreeNode node, bool inNewTabPage = false)
}
else
{
ChangingSelection();
activeView?.ScrollIntoView(node);
SelectedItem = node;
}
Expand All @@ -519,6 +528,7 @@ internal void SelectNodes(IEnumerable<SharpTreeNode> nodes)
return;
}

ChangingSelection();
SelectedItems.Clear();
SelectedItems.AddRange(nodesList);
}
Expand Down Expand Up @@ -691,20 +701,17 @@ void TreeView_SelectionChanged()
{
if (SelectedItems.Count > 0)
{
bool isRightButtonPressed = Mouse.RightButton == MouseButtonState.Pressed;
bool isLeftButtonPressed = Mouse.LeftButton == MouseButtonState.Pressed;

if (isLeftButtonPressed || isRightButtonPressed)
if (!isInternalSelectionChanging)
{
// record history only if change is initiated by user
// record history only if change is initiated by user input
var activeTabPage = DockWorkspace.Instance.ActiveTabPage;
var currentState = activeTabPage.GetState();
if (currentState != null)
history.UpdateCurrent(new NavigationState(activeTabPage, currentState));
history.Record(new NavigationState(activeTabPage, SelectedItems));
}

var delayDecompilationRequestDueToContextMenu = isRightButtonPressed;
var delayDecompilationRequestDueToContextMenu = Mouse.RightButton == MouseButtonState.Pressed;

if (!delayDecompilationRequestDueToContextMenu)
{
Expand Down Expand Up @@ -855,6 +862,7 @@ public void Refresh()

private void UnselectAll()
{
ChangingSelection();
SelectedItems.Clear();
}

Expand Down
1 change: 1 addition & 0 deletions ILSpy/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

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

<Window.TaskbarItemInfo>
Expand Down

0 comments on commit 2682dcb

Please sign in to comment.