Browse Source

add support for Backspace and Delete in virtual space

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
b32efa69cf
  1. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EmptySelection.cs
  2. 14
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Selection.cs
  3. 7
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SimpleSelection.cs
  4. 3
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs
  5. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/BackgroundGeometryBuilder.cs

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EmptySelection.cs

@ -56,6 +56,7 @@ namespace ICSharpCode.AvalonEdit.Editing
textArea.Document.Insert(textArea.Caret.Offset, newText); textArea.Document.Insert(textArea.Caret.Offset, newText);
} }
} }
textArea.Caret.VisualColumn = -1;
} }
public override int Length { public override int Length {

14
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Selection.cs

@ -81,11 +81,19 @@ namespace ICSharpCode.AvalonEdit.Editing
internal string AddSpacesIfRequired(string newText, TextViewPosition pos) internal string AddSpacesIfRequired(string newText, TextViewPosition pos)
{ {
if (textArea.Options.EnableVirtualSpace) { if (textArea.Options.EnableVirtualSpace && !string.IsNullOrEmpty(newText)) {
var vLine = textArea.TextView.GetOrConstructVisualLine(textArea.Document.GetLineByNumber(pos.Line)); var line = textArea.Document.GetLineByNumber(pos.Line);
string lineText = textArea.Document.GetText(line);
var vLine = textArea.TextView.GetOrConstructVisualLine(line);
int colDiff = pos.VisualColumn - vLine.VisualLength; int colDiff = pos.VisualColumn - vLine.VisualLength;
if (colDiff > 0) { if (colDiff > 0) {
string additionalSpaces = new string(' ', colDiff); string additionalSpaces = "";
if (!textArea.Options.ConvertTabsToSpaces && lineText.Trim('\t').Length == 0) {
int tabCount = (int)(colDiff / textArea.Options.IndentationSize);
additionalSpaces = new string('\t', tabCount);
colDiff -= tabCount * textArea.Options.IndentationSize;
}
additionalSpaces += new string(' ', colDiff);
return additionalSpaces + newText; return additionalSpaces + newText;
} }
} }

7
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SimpleSelection.cs

@ -56,7 +56,10 @@ namespace ICSharpCode.AvalonEdit.Editing
if (segmentsToDelete[i].Offset == SurroundingSegment.Offset && segmentsToDelete[i].Length == SurroundingSegment.Length) { if (segmentsToDelete[i].Offset == SurroundingSegment.Offset && segmentsToDelete[i].Length == SurroundingSegment.Length) {
newText = AddSpacesIfRequired(newText, start); newText = AddSpacesIfRequired(newText, start);
} }
int vc = textArea.Caret.VisualColumn;
textArea.Caret.Offset = segmentsToDelete[i].EndOffset; textArea.Caret.Offset = segmentsToDelete[i].EndOffset;
if (string.IsNullOrEmpty(newText))
textArea.Caret.VisualColumn = vc;
textArea.Document.Replace(segmentsToDelete[i], newText); textArea.Document.Replace(segmentsToDelete[i], newText);
} else { } else {
textArea.Document.Remove(segmentsToDelete[i]); textArea.Document.Remove(segmentsToDelete[i]);
@ -89,8 +92,8 @@ namespace ICSharpCode.AvalonEdit.Editing
throw new ArgumentNullException("e"); throw new ArgumentNullException("e");
return Selection.Create( return Selection.Create(
textArea, textArea,
e.GetNewOffset(startOffset, AnchorMovementType.Default), new TextViewPosition(textArea.Document.GetLocation(e.GetNewOffset(startOffset, AnchorMovementType.Default)), start.VisualColumn),
e.GetNewOffset(endOffset, AnchorMovementType.Default) new TextViewPosition(textArea.Document.GetLocation(e.GetNewOffset(endOffset, AnchorMovementType.Default)), end.VisualColumn)
); );
} }

3
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

@ -421,6 +421,9 @@ namespace ICSharpCode.AvalonEdit.Editing
} }
} }
/// <summary>
/// Clears the current selection.
/// </summary>
public void ClearSelection() public void ClearSelection()
{ {
this.Selection = emptySelection; this.Selection = emptySelection;

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/BackgroundGeometryBuilder.cs

@ -171,8 +171,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
} }
} }
if (segmentEndVC >= vl.VisualLength) { if (segmentEndVC >= vl.VisualLength) {
double left = (segmentStartVC > vl.VisualLength ? vl.GetTextLineVisualXPosition(line, segmentStartVC) : line.Width) - scrollOffset.X; double left = (segmentStartVC > vl.VisualLength ? vl.GetTextLineVisualXPosition(lastTextLine, segmentStartVC) : line.Width) - scrollOffset.X;
double right = (segmentEndVC == int.MaxValue ? Math.Max(((IScrollInfo)textView).ExtentWidth, ((IScrollInfo)textView).ViewportWidth) : vl.GetTextLineVisualXPosition(line, segmentEndVC)) - scrollOffset.X; double right = ((segmentEndVC == int.MaxValue || line != lastTextLine) ? Math.Max(((IScrollInfo)textView).ExtentWidth, ((IScrollInfo)textView).ViewportWidth) : vl.GetTextLineVisualXPosition(lastTextLine, segmentEndVC)) - scrollOffset.X;
Rect extendSelection = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height); Rect extendSelection = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height);
if (!lastRect.IsEmpty) { if (!lastRect.IsEmpty) {
if (extendSelection.IntersectsWith(lastRect)) { if (extendSelection.IntersectsWith(lastRect)) {

Loading…
Cancel
Save