Browse Source

fix ArgumentException occurring when pressing backspace at the start of the document, introduced by ebb5d25c

pull/59/merge
Siegfried Pammer 12 years ago
parent
commit
a849a6f938
  1. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

@ -239,6 +239,10 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -239,6 +239,10 @@ namespace ICSharpCode.AvalonEdit.Editing
double desiredXPos = textArea.Caret.DesiredXPos;
TextViewPosition endPos = CaretNavigationCommandHandler.GetNewCaretPosition(
textArea.TextView, startPos, caretMovement, enableVirtualSpace, ref desiredXPos);
// GetNewCaretPosition may return (0,0) as new position,
// 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 select the text to be deleted; just reuse the ReplaceSelectionWithText logic
var sel = new SimpleSelection(textArea, startPos, endPos);
sel.ReplaceSelectionWithText(string.Empty);

Loading…
Cancel
Save