diff --git a/ICSharpCode.AvalonEdit/Editing/RectangleSelection.cs b/ICSharpCode.AvalonEdit/Editing/RectangleSelection.cs index 60888d88..2834b2e0 100644 --- a/ICSharpCode.AvalonEdit/Editing/RectangleSelection.cs +++ b/ICSharpCode.AvalonEdit/Editing/RectangleSelection.cs @@ -288,12 +288,15 @@ int GetVisualColumnFromXPos(int line, double xPos) /// public override Selection UpdateOnDocumentChange(DocumentChangeEventArgs e) { - TextLocation newStartLocation = textArea.Document.GetLocation(e.GetNewOffset(topLeftOffset, AnchorMovementType.AfterInsertion)); - TextLocation newEndLocation = textArea.Document.GetLocation(e.GetNewOffset(bottomRightOffset, AnchorMovementType.BeforeInsertion)); - - return new RectangleSelection(textArea, - new TextViewPosition(newStartLocation, GetVisualColumnFromXPos(newStartLocation.Line, startXPos)), - new TextViewPosition(newEndLocation, GetVisualColumnFromXPos(newEndLocation.Line, endXPos))); + // we don't want to recalculate the whole selection, as this is called for every line within the selection + // and it can cause selection changes to take a wildly-long time. + return this; + //TextLocation newStartLocation = textArea.Document.GetLocation(e.GetNewOffset(topLeftOffset, AnchorMovementType.AfterInsertion)); + //TextLocation newEndLocation = textArea.Document.GetLocation(e.GetNewOffset(bottomRightOffset, AnchorMovementType.BeforeInsertion)); + + //return new RectangleSelection(textArea, + // new TextViewPosition(newStartLocation, GetVisualColumnFromXPos(newStartLocation.Line, startXPos)), + // new TextViewPosition(newEndLocation, GetVisualColumnFromXPos(newEndLocation.Line, endXPos))); } /// @@ -331,7 +334,10 @@ public override void ReplaceSelectionWithText(string newText) pos = new TextViewPosition(document.GetLocation(editOffset + firstInsertionLength)); textArea.ClearSelection(); } - textArea.Caret.Position = textArea.TextView.GetPosition(new Point(GetXPos(textArea, pos), textArea.TextView.GetVisualTopByDocumentLine(Math.Max(startLine, endLine)))).GetValueOrDefault(); + TextViewPosition? calculatedPositon = textArea.TextView.GetPosition(new Point(GetXPos(textArea, pos), textArea.TextView.GetVisualTopByDocumentLine(Math.Max(startLine, endLine)))); + if (calculatedPositon != null) { + textArea.Caret.Position = calculatedPositon.GetValueOrDefault(); + } } }