From 4239abbc071bb5927e33320731bcf46c40ea5153 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 8 May 2026 17:20:16 +0200 Subject: [PATCH] Keep Copy / Select All in the decompiler context menu Replacing the default editor menu with the MEF-driven one stripped the standard text-edit affordances. Always seed Copy and Select All at the top of the built menu (Copy disabled when there's no selection); MEF entries follow after a separator. Right-clicking plain text now produces a usable menu instead of nothing. Assisted-by: Claude:claude-opus-4-7:Claude Code --- ILSpy/TextView/DecompilerTextView.axaml.cs | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ILSpy/TextView/DecompilerTextView.axaml.cs b/ILSpy/TextView/DecompilerTextView.axaml.cs index 7fc164948..6a08ecb9e 100644 --- a/ILSpy/TextView/DecompilerTextView.axaml.cs +++ b/ILSpy/TextView/DecompilerTextView.axaml.cs @@ -195,17 +195,30 @@ namespace ILSpy.TextView TextView = this, Reference = lastRightClickedSegment, }; - var built = ContextMenuProvider.Build(contextMenuEntries, ctx); - if (built == null) - { - e.Cancel = true; - return; - } menu.Items.Clear(); - foreach (var item in built.Items.Cast().ToArray()) + + // Always-available editor commands first — Copy / Select All come "for free" on + // AvaloniaEdit via keyboard shortcuts but the default control template doesn't + // ship a context menu, so right-click in plain text would otherwise produce + // nothing. The MEF-discovered entries (Show in metadata, etc.) follow. + var copyItem = new MenuItem { Header = "Copy", InputGesture = new KeyGesture(Key.C, KeyModifiers.Control) }; + copyItem.Click += (_, _) => Editor.Copy(); + copyItem.IsEnabled = !string.IsNullOrEmpty(Editor.SelectedText); + menu.Items.Add(copyItem); + + var selectAllItem = new MenuItem { Header = "Select All", InputGesture = new KeyGesture(Key.A, KeyModifiers.Control) }; + selectAllItem.Click += (_, _) => Editor.SelectAll(); + menu.Items.Add(selectAllItem); + + var built = ContextMenuProvider.Build(contextMenuEntries, ctx); + if (built != null) { - built.Items.Remove(item); - menu.Items.Add(item); + menu.Items.Add(new Separator()); + foreach (var item in built.Items.Cast().ToArray()) + { + built.Items.Remove(item); + menu.Items.Add(item); + } } }