Skip to content

Commit a5691fa

Browse files
Fix #22, fix #57: RectangleSelection does not handle backspace and delete key
1 parent 6200cab commit a5691fa

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,13 @@ static ExecutedRoutedEventHandler OnDelete(CaretMovementType caretMovement)
258258
// thus we need to validate endPos before using it in the selection.
259259
if (endPos.Line < 1 || endPos.Column < 1)
260260
endPos = new TextViewPosition(Math.Max(endPos.Line, 1), Math.Max(endPos.Column, 1));
261+
// Don't do anything if the number of lines of a rectangular selection would be changed by the deletion.
262+
if (textArea.Selection is RectangleSelection && startPos.Line != endPos.Line)
263+
return;
261264
// Don't select the text to be deleted; just reuse the ReplaceSelectionWithText logic
262-
var sel = new SimpleSelection(textArea, startPos, endPos);
263-
sel.ReplaceSelectionWithText(string.Empty);
265+
// Reuse the existing selection, so that we continue using the same logic
266+
textArea.Selection.StartSelectionOrSetEndpoint(startPos, endPos)
267+
.ReplaceSelectionWithText(string.Empty);
264268
} else {
265269
textArea.RemoveSelectedText();
266270
}

0 commit comments

Comments
 (0)