internal void DeleteSelection (Selection selection) { if (selection.IsEmpty) throw new ArgumentNullException ("selection was empty."); switch (selection.SelectionMode) { case SelectionMode.Normal: var segment = selection.GetSelectionRange (this); int len = System.Math.Min (segment.Length, Document.TextLength - segment.Offset); var loc = selection.Anchor < selection.Lead ? selection.Anchor : selection.Lead; caret.Location = loc; EnsureCaretIsNotVirtual (); if (len > 0) Remove (segment.Offset, len); caret.Location = loc; break; case SelectionMode.Block: DocumentLocation visStart = LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); bool preserve = Caret.PreserveSelection; Caret.PreserveSelection = true; for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (this, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (this, endCol) - 1, curLine.Length); if (col1 >= col2) continue; Remove (curLine.Offset + col1, col2 - col1); if (Caret.Line == lineNr && Caret.Column >= col1) Caret.Column = col1 + 1; } int column = System.Math.Min (selection.Anchor.Column, selection.Lead.Column); MainSelection = selection.WithRange ( new DocumentLocation (selection.Anchor.Line, column), new DocumentLocation (selection.Lead.Line, column) ); Caret.PreserveSelection = preserve; break; } FixVirtualIndentation (); }