Skip to content

Commit 379439b

Browse files
committed
Fix #43 alternate shortcut for copy (Ctrl+Ins) not working if Options.AllowToggleOverstrikeMode is enabled.
Based on @nippur72's fix in #44.
1 parent 0e8be49 commit 379439b

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

ICSharpCode.AvalonEdit/AvalonEditCommands.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ namespace ICSharpCode.AvalonEdit
2626
/// </summary>
2727
public static class AvalonEditCommands
2828
{
29+
/// <summary>
30+
/// Toggles Overstrike mode
31+
/// The default shortcut is Ins.
32+
/// </summary>
33+
public static readonly RoutedCommand ToggleOverstrike = new RoutedCommand(
34+
"ToggleOverstrike", typeof(TextEditor),
35+
new InputGestureCollection {
36+
new KeyGesture(Key.Insert)
37+
});
38+
2939
/// <summary>
3040
/// Deletes the current line.
3141
/// The default shortcut is Ctrl+D.

ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static EditingCommandHandler()
7878
CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, OnCut, CanCutOrCopy));
7979
CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPaste, CanPaste));
8080

81+
CommandBindings.Add(new CommandBinding(AvalonEditCommands.ToggleOverstrike, OnToggleOverstrike));
8182
CommandBindings.Add(new CommandBinding(AvalonEditCommands.DeleteLine, OnDeleteLine));
8283

8384
CommandBindings.Add(new CommandBinding(AvalonEditCommands.RemoveLeadingWhitespace, OnRemoveLeadingWhitespace));
@@ -484,6 +485,15 @@ internal static string GetTextToPaste(DataObjectPastingEventArgs pastingEventArg
484485
}
485486
#endregion
486487

488+
#region Toggle Overstrike
489+
static void OnToggleOverstrike(object target, ExecutedRoutedEventArgs args)
490+
{
491+
TextArea textArea = GetTextArea(target);
492+
if (textArea != null && textArea.Options.AllowToggleOverstrikeMode)
493+
textArea.OverstrikeMode = !textArea.OverstrikeMode;
494+
}
495+
#endregion
496+
487497
#region DeleteLine
488498
static void OnDeleteLine(object target, ExecutedRoutedEventArgs args)
489499
{

ICSharpCode.AvalonEdit/Editing/TextArea.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -971,13 +971,6 @@ public IIndentationStrategy IndentationStrategy {
971971
protected override void OnPreviewKeyDown(KeyEventArgs e)
972972
{
973973
base.OnPreviewKeyDown(e);
974-
975-
if (!e.Handled && e.Key == Key.Insert && this.Options.AllowToggleOverstrikeMode) {
976-
this.OverstrikeMode = !this.OverstrikeMode;
977-
e.Handled = true;
978-
return;
979-
}
980-
981974
foreach (TextAreaStackedInputHandler h in stackedInputHandlers) {
982975
if (e.Handled)
983976
break;

0 commit comments

Comments
 (0)