Index: /branches/CodeEditor/HeuristicLab.CodeEditor/3.4/CodeEditor.cs
===================================================================
--- /branches/CodeEditor/HeuristicLab.CodeEditor/3.4/CodeEditor.cs	(revision 11742)
+++ /branches/CodeEditor/HeuristicLab.CodeEditor/3.4/CodeEditor.cs	(revision 11743)
@@ -24,5 +24,4 @@
 using System.Collections.Generic;
 using System.ComponentModel;
-using System.Linq;
 using System.Reflection;
 using System.Threading.Tasks;
@@ -54,5 +53,4 @@
     private const double DefaultTextEditorFontSize = 13.0;
     private const bool DefaultTextEditorShowLineNumbers = true;
-    private const bool DefaultTextEditorShowEndOfLine = true;
     private const bool DefaultTextEditorShowSpaces = true;
     private const bool DefaultTextEditorShowTabs = true;
@@ -134,10 +132,4 @@
     }
 
-    [DefaultValue(DefaultTextEditorShowEndOfLine)]
-    public bool TextEditorShowEndOfLine {
-      get { return TextEditor.Options.ShowEndOfLine; }
-      set { TextEditor.Options.ShowEndOfLine = value; }
-    }
-
     [DefaultValue(DefaultTextEditorShowSpaces)]
     public bool TextEditorShowSpaces {
@@ -230,5 +222,4 @@
       TextEditorSyntaxHighlighting = DefaultTextEditorSyntaxHighlighting;
       TextEditorShowLineNumbers = DefaultTextEditorShowLineNumbers;
-      TextEditorShowEndOfLine = DefaultTextEditorShowEndOfLine;
       TextEditorShowSpaces = DefaultTextEditorShowSpaces;
       TextEditorShowTabs = DefaultTextEditorShowTabs;
@@ -241,4 +232,5 @@
       TextEditor.FontFamily = new Media.FontFamily(DefaultTextEditorFontFamily);
       TextEditor.FontSize = DefaultTextEditorFontSize;
+      TextEditor.Options.EnableVirtualSpace = true;
 
       TextEditor.TextChanged += (sender, args) => {
@@ -281,24 +273,35 @@
       var textArea = TextEditor.TextArea;
       var selection = textArea.Selection;
-
-      int selectionStart, selectionEnd;
-      if (!(selection is RectangleSelection) && selection.IsEmpty) {
-        selectionStart = selectionEnd = TextEditor.SelectionStart;
+      var caret = textArea.Caret;
+
+      var selectionStartPosition = selection.StartPosition;
+      var selectionEndPosition = selection.EndPosition;
+      var caretPosition = caret.Position;
+      int caretOffset = caret.Offset;
+
+      bool advancedPositionCalcualtion = selection is RectangleSelection || !selection.IsEmpty;
+
+      int selectionStartOffset, selectionEndOffset;
+      if (advancedPositionCalcualtion) {
+        if (selectionStartPosition.CompareTo(selectionEndPosition) > 0) {
+          var temp = selectionStartPosition;
+          selectionStartPosition = selectionEndPosition;
+          selectionEndPosition = temp;
+        }
+        selectionStartOffset = Doc.GetOffset(selectionStartPosition.Location);
+        selectionEndOffset = Doc.GetOffset(selectionEndPosition.Location);
       } else {
-        selectionStart = Doc.GetOffset(selection.StartPosition.Location);
-        selectionEnd = Doc.GetOffset(selection.EndPosition.Location);
-        if (selectionStart > selectionEnd) {
-          int temp = selectionStart;
-          selectionStart = selectionEnd;
-          selectionEnd = temp;
-        }
+        selectionStartOffset = selectionEndOffset = TextEditor.SelectionStart;
       }
 
       int selectionLength = selection.Length;
-      var selectionSegments = selection.Segments;
-      int caretOffset = TextEditor.CaretOffset;
-
-      var startLine = Doc.GetLineByOffset(selectionStart);
-      var endLine = Doc.GetLineByOffset(selectionEnd);
+
+      var startLine = Doc.GetLineByOffset(selectionStartOffset);
+      var endLine = Doc.GetLineByOffset(selectionEndOffset);
+
+      if (selection.IsMultiline && selectionEndOffset == endLine.Offset) {
+        if (movementDirection == MovementDirection.Down && endLine.TotalLength == 0) return;
+        endLine = endLine.PreviousLine;
+      }
 
       if (movementDirection == MovementDirection.Up && startLine.LineNumber == 1) return;
@@ -312,4 +315,6 @@
       string secondaryText = Doc.GetText(secondaryLine.Offset, secondaryLine.Length);
       string secondaryDelimiter = Doc.GetText(secondaryLine.EndOffset, secondaryLine.DelimiterLength);
+
+      if (string.IsNullOrEmpty(primaryText + primaryDelimiter) || string.IsNullOrEmpty(secondaryText + secondaryDelimiter)) return;
 
       if (movementDirection == MovementDirection.Up) {
@@ -317,5 +322,5 @@
         Doc.Replace(secondaryLine.Offset, replacementText.Length, replacementText);
         int correctionLength = secondaryText.Length + secondaryDelimiter.Length;
-        selectionStart -= correctionLength;
+        selectionStartOffset -= correctionLength;
         caretOffset -= correctionLength;
       } else {
@@ -323,22 +328,40 @@
         Doc.Replace(startLine.Offset, replacementText.Length, replacementText);
         int correctionLength = secondaryText.Length + primaryDelimiter.Length;
-        selectionStart += correctionLength;
+        selectionStartOffset += correctionLength;
         caretOffset += correctionLength;
       }
 
-      if (textArea.Selection is RectangleSelection) {
-        textArea.ClearSelection();
-        int lowestOffset = selectionSegments.Min(x => x.StartOffset);
-        int highestOffset = selectionSegments.Max(x => x.EndOffset);
-        selectionLength = highestOffset - lowestOffset;
-        var startPosition = new TextViewPosition(Doc.GetLocation(selectionStart));
-        var endPosition = new TextViewPosition(Doc.GetLocation(selectionStart + selectionLength));
-        textArea.Selection = new RectangleSelection(textArea, startPosition, endPosition);
+      if (advancedPositionCalcualtion) {
+        var newSelectionStartLocation = Doc.GetLocation(selectionStartOffset);
+        int selectionLineOffset = newSelectionStartLocation.Line - Math.Min(selectionStartPosition.Line, selectionEndPosition.Line);
+        selectionStartPosition.Line += selectionLineOffset;
+        selectionEndPosition.Line += selectionLineOffset;
+        if (selectionEndPosition.Line > Doc.LineCount) {
+          var newLocation = Doc.GetLocation(Doc.TextLength);
+          selectionEndPosition.Line = newLocation.Line;
+          selectionEndPosition.Column = newLocation.Column;
+          selectionEndPosition.VisualColumn = newLocation.Column - 1;
+          selectionEndPosition.IsAtEndOfLine = selectionStartPosition.IsAtEndOfLine; // actual value does not matter; needed for comparison
+        }
+
+        if (selectionStartPosition == selectionEndPosition)
+          textArea.ClearSelection();
+        else {
+          if (selection is RectangleSelection)
+            textArea.Selection = new RectangleSelection(textArea, selectionStartPosition, selectionEndPosition);
+          else
+            textArea.Selection = new SimpleSelection(textArea, selectionStartPosition, selectionEndPosition);
+        }
       } else {
-        TextEditor.SelectionStart = selectionStart;
+        TextEditor.SelectionStart = selectionStartOffset;
         TextEditor.SelectionLength = selectionLength;
       }
 
-      TextEditor.CaretOffset = caretOffset;
+      var newCaretLocation = Doc.GetLocation(Math.Min(caretOffset, Doc.TextLength));
+      var newCaretPosition = new TextViewPosition(newCaretLocation);
+      if (caretPosition.VisualColumn > caretPosition.Column) {
+        newCaretPosition.VisualColumn = caretPosition.VisualColumn;
+      }
+      caret.Position = newCaretPosition;
     }
 
Index: /branches/CodeEditor/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Editing/SimpleSelection.cs
===================================================================
--- /branches/CodeEditor/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Editing/SimpleSelection.cs	(revision 11742)
+++ /branches/CodeEditor/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Editing/SimpleSelection.cs	(revision 11743)
@@ -30,5 +30,5 @@
 	/// A simple selection.
 	/// </summary>
-	sealed class SimpleSelection : Selection
+	public sealed class SimpleSelection : Selection
 	{
 		readonly TextViewPosition start, end;
@@ -38,5 +38,5 @@
 		/// Creates a new SimpleSelection instance.
 		/// </summary>
-		internal SimpleSelection(TextArea textArea, TextViewPosition start, TextViewPosition end)
+		public SimpleSelection(TextArea textArea, TextViewPosition start, TextViewPosition end)
 			: base(textArea)
 		{
