Skip to content

Commit

Permalink
RectangleSelection does not handle backspace and delete key AvaloniaU…
Browse files Browse the repository at this point in the history
  • Loading branch information
danwalmsley committed Nov 20, 2020
1 parent 1bd3b55 commit 4e39753
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/AvaloniaEdit/Editing/EditingCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,13 @@ private static EventHandler<ExecutedRoutedEventArgs> OnDelete(CaretMovementType
// thus we need to validate endPos before using it in the selection.
if (endPos.Line < 1 || endPos.Column < 1)
endPos = new TextViewPosition(Math.Max(endPos.Line, 1), Math.Max(endPos.Column, 1));
// Don't do anything if the number of lines of a rectangular selection would be changed by the deletion.
if (textArea.Selection is RectangleSelection && startPos.Line != endPos.Line)
return;
// Don't select the text to be deleted; just reuse the ReplaceSelectionWithText logic
var sel = new SimpleSelection(textArea, startPos, endPos);
sel.ReplaceSelectionWithText(string.Empty);
// Reuse the existing selection, so that we continue using the same logic
textArea.Selection.StartSelectionOrSetEndpoint(startPos, endPos)
.ReplaceSelectionWithText(string.Empty);
}
else
{
Expand Down

0 comments on commit 4e39753

Please sign in to comment.