From 3bfe69c36543def9c53f1a235815d7f4bb5d91cd Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Sat, 15 Jun 2013 23:06:23 +0200 Subject: [PATCH] Deleting of all lines affected by a selection using Ctrl+D. --- .../Editing/EditingCommandHandler.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs index 3e8e316524..26d0399e63 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; +using System.Net; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Documents; @@ -426,8 +427,18 @@ namespace ICSharpCode.AvalonEdit.Editing { TextArea textArea = GetTextArea(target); if (textArea != null && textArea.Document != null) { - DocumentLine currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line); - textArea.Selection = Selection.Create(textArea, currentLine.Offset, currentLine.Offset + currentLine.TotalLength); + int firstLineIndex, lastLineIndex; + if (textArea.Selection.Length == 0) { + // There is no selection, simply delete current line + firstLineIndex = lastLineIndex = textArea.Caret.Line; + } else { + // There is a selection, remove all lines affected by it + firstLineIndex = textArea.Selection.StartPosition.Line; + lastLineIndex = textArea.Selection.EndPosition.Line; + } + DocumentLine startLine = textArea.Document.GetLineByNumber(firstLineIndex); + DocumentLine endLine = textArea.Document.GetLineByNumber(lastLineIndex); + textArea.Selection = Selection.Create(textArea, startLine.Offset, endLine.Offset + endLine.TotalLength); textArea.RemoveSelectedText(); args.Handled = true; }