Browse Source

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
pull/3755/head
Siegfried Pammer 2 months ago
parent
commit
4239abbc07
  1. 31
      ILSpy/TextView/DecompilerTextView.axaml.cs

31
ILSpy/TextView/DecompilerTextView.axaml.cs

@ -195,17 +195,30 @@ namespace ILSpy.TextView @@ -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<Control>().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<Control>().ToArray())
{
built.Items.Remove(item);
menu.Items.Add(item);
}
}
}

Loading…
Cancel
Save