Changeset 11743 for branches/CodeEditor/HeuristicLab.CodeEditor
- Timestamp:
- 01/09/15 16:42:32 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/CodeEditor.cs
r11741 r11743 24 24 using System.Collections.Generic; 25 25 using System.ComponentModel; 26 using System.Linq;27 26 using System.Reflection; 28 27 using System.Threading.Tasks; … … 54 53 private const double DefaultTextEditorFontSize = 13.0; 55 54 private const bool DefaultTextEditorShowLineNumbers = true; 56 private const bool DefaultTextEditorShowEndOfLine = true;57 55 private const bool DefaultTextEditorShowSpaces = true; 58 56 private const bool DefaultTextEditorShowTabs = true; … … 134 132 } 135 133 136 [DefaultValue(DefaultTextEditorShowEndOfLine)]137 public bool TextEditorShowEndOfLine {138 get { return TextEditor.Options.ShowEndOfLine; }139 set { TextEditor.Options.ShowEndOfLine = value; }140 }141 142 134 [DefaultValue(DefaultTextEditorShowSpaces)] 143 135 public bool TextEditorShowSpaces { … … 230 222 TextEditorSyntaxHighlighting = DefaultTextEditorSyntaxHighlighting; 231 223 TextEditorShowLineNumbers = DefaultTextEditorShowLineNumbers; 232 TextEditorShowEndOfLine = DefaultTextEditorShowEndOfLine;233 224 TextEditorShowSpaces = DefaultTextEditorShowSpaces; 234 225 TextEditorShowTabs = DefaultTextEditorShowTabs; … … 241 232 TextEditor.FontFamily = new Media.FontFamily(DefaultTextEditorFontFamily); 242 233 TextEditor.FontSize = DefaultTextEditorFontSize; 234 TextEditor.Options.EnableVirtualSpace = true; 243 235 244 236 TextEditor.TextChanged += (sender, args) => { … … 281 273 var textArea = TextEditor.TextArea; 282 274 var selection = textArea.Selection; 283 284 int selectionStart, selectionEnd; 285 if (!(selection is RectangleSelection) && selection.IsEmpty) { 286 selectionStart = selectionEnd = TextEditor.SelectionStart; 275 var caret = textArea.Caret; 276 277 var selectionStartPosition = selection.StartPosition; 278 var selectionEndPosition = selection.EndPosition; 279 var caretPosition = caret.Position; 280 int caretOffset = caret.Offset; 281 282 bool advancedPositionCalcualtion = selection is RectangleSelection || !selection.IsEmpty; 283 284 int selectionStartOffset, selectionEndOffset; 285 if (advancedPositionCalcualtion) { 286 if (selectionStartPosition.CompareTo(selectionEndPosition) > 0) { 287 var temp = selectionStartPosition; 288 selectionStartPosition = selectionEndPosition; 289 selectionEndPosition = temp; 290 } 291 selectionStartOffset = Doc.GetOffset(selectionStartPosition.Location); 292 selectionEndOffset = Doc.GetOffset(selectionEndPosition.Location); 287 293 } else { 288 selectionStart = Doc.GetOffset(selection.StartPosition.Location); 289 selectionEnd = Doc.GetOffset(selection.EndPosition.Location); 290 if (selectionStart > selectionEnd) { 291 int temp = selectionStart; 292 selectionStart = selectionEnd; 293 selectionEnd = temp; 294 } 294 selectionStartOffset = selectionEndOffset = TextEditor.SelectionStart; 295 295 } 296 296 297 297 int selectionLength = selection.Length; 298 var selectionSegments = selection.Segments; 299 int caretOffset = TextEditor.CaretOffset; 300 301 var startLine = Doc.GetLineByOffset(selectionStart); 302 var endLine = Doc.GetLineByOffset(selectionEnd); 298 299 var startLine = Doc.GetLineByOffset(selectionStartOffset); 300 var endLine = Doc.GetLineByOffset(selectionEndOffset); 301 302 if (selection.IsMultiline && selectionEndOffset == endLine.Offset) { 303 if (movementDirection == MovementDirection.Down && endLine.TotalLength == 0) return; 304 endLine = endLine.PreviousLine; 305 } 303 306 304 307 if (movementDirection == MovementDirection.Up && startLine.LineNumber == 1) return; … … 312 315 string secondaryText = Doc.GetText(secondaryLine.Offset, secondaryLine.Length); 313 316 string secondaryDelimiter = Doc.GetText(secondaryLine.EndOffset, secondaryLine.DelimiterLength); 317 318 if (string.IsNullOrEmpty(primaryText + primaryDelimiter) || string.IsNullOrEmpty(secondaryText + secondaryDelimiter)) return; 314 319 315 320 if (movementDirection == MovementDirection.Up) { … … 317 322 Doc.Replace(secondaryLine.Offset, replacementText.Length, replacementText); 318 323 int correctionLength = secondaryText.Length + secondaryDelimiter.Length; 319 selectionStart -= correctionLength;324 selectionStartOffset -= correctionLength; 320 325 caretOffset -= correctionLength; 321 326 } else { … … 323 328 Doc.Replace(startLine.Offset, replacementText.Length, replacementText); 324 329 int correctionLength = secondaryText.Length + primaryDelimiter.Length; 325 selectionStart += correctionLength;330 selectionStartOffset += correctionLength; 326 331 caretOffset += correctionLength; 327 332 } 328 333 329 if (textArea.Selection is RectangleSelection) { 330 textArea.ClearSelection(); 331 int lowestOffset = selectionSegments.Min(x => x.StartOffset); 332 int highestOffset = selectionSegments.Max(x => x.EndOffset); 333 selectionLength = highestOffset - lowestOffset; 334 var startPosition = new TextViewPosition(Doc.GetLocation(selectionStart)); 335 var endPosition = new TextViewPosition(Doc.GetLocation(selectionStart + selectionLength)); 336 textArea.Selection = new RectangleSelection(textArea, startPosition, endPosition); 334 if (advancedPositionCalcualtion) { 335 var newSelectionStartLocation = Doc.GetLocation(selectionStartOffset); 336 int selectionLineOffset = newSelectionStartLocation.Line - Math.Min(selectionStartPosition.Line, selectionEndPosition.Line); 337 selectionStartPosition.Line += selectionLineOffset; 338 selectionEndPosition.Line += selectionLineOffset; 339 if (selectionEndPosition.Line > Doc.LineCount) { 340 var newLocation = Doc.GetLocation(Doc.TextLength); 341 selectionEndPosition.Line = newLocation.Line; 342 selectionEndPosition.Column = newLocation.Column; 343 selectionEndPosition.VisualColumn = newLocation.Column - 1; 344 selectionEndPosition.IsAtEndOfLine = selectionStartPosition.IsAtEndOfLine; // actual value does not matter; needed for comparison 345 } 346 347 if (selectionStartPosition == selectionEndPosition) 348 textArea.ClearSelection(); 349 else { 350 if (selection is RectangleSelection) 351 textArea.Selection = new RectangleSelection(textArea, selectionStartPosition, selectionEndPosition); 352 else 353 textArea.Selection = new SimpleSelection(textArea, selectionStartPosition, selectionEndPosition); 354 } 337 355 } else { 338 TextEditor.SelectionStart = selectionStart ;356 TextEditor.SelectionStart = selectionStartOffset; 339 357 TextEditor.SelectionLength = selectionLength; 340 358 } 341 359 342 TextEditor.CaretOffset = caretOffset; 360 var newCaretLocation = Doc.GetLocation(Math.Min(caretOffset, Doc.TextLength)); 361 var newCaretPosition = new TextViewPosition(newCaretLocation); 362 if (caretPosition.VisualColumn > caretPosition.Column) { 363 newCaretPosition.VisualColumn = caretPosition.VisualColumn; 364 } 365 caret.Position = newCaretPosition; 343 366 } 344 367
Note: See TracChangeset
for help on using the changeset viewer.