Browse Source

fix #298: Insert with cursor: Indentation is wrong

pull/331/head
Siegfried Pammer 12 years ago
parent
commit
4bb6ea86ac
  1. 17
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs
  2. 3
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/InsertionPoint.cs

17
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs

@ -149,13 +149,16 @@ namespace CSharpBinding.Refactoring @@ -149,13 +149,16 @@ namespace CSharpBinding.Refactoring
args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) {
args.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
}
foreach (var node in nodes.Reverse ()) {
int indentLevel = currentScript.GetIndentLevelAt(target.GetOffset(args.InsertionPoint.Location));
int offset = currentScript.GetCurrentOffset(args.InsertionPoint.Location);
int indentLevel = currentScript.GetIndentLevelAt(offset);
foreach (var node in nodes.Reverse()) {
var output = currentScript.OutputNode(indentLevel, node);
var offset = target.GetOffset(args.InsertionPoint.Location);
var delta = args.InsertionPoint.Insert(target, output.Text);
int delta = args.InsertionPoint.Insert(target, output.Text);
output.RegisterTrackedSegments(currentScript, delta + offset);
}
currentScript.FormatText(nodes);
tcs.SetResult(currentScript);
}
layer.Dispose();
@ -310,14 +313,14 @@ namespace CSharpBinding.Refactoring @@ -310,14 +313,14 @@ namespace CSharpBinding.Refactoring
protected override void OnRender(DrawingContext drawingContext)
{
DrawLineForInserionPoint(CurrentInsertionPoint, markerPen, drawingContext);
DrawLineForInsertionPoint(CurrentInsertionPoint, markerPen, drawingContext);
if (insertionPointNextToMouse > -1 && insertionPointNextToMouse != CurrentInsertionPoint)
DrawLineForInserionPoint(insertionPointNextToMouse, tempMarkerPen, drawingContext);
DrawLineForInsertionPoint(insertionPointNextToMouse, tempMarkerPen, drawingContext);
SetGroupBoxPosition(); // HACK
}
void DrawLineForInserionPoint(int index, Pen pen, DrawingContext drawingContext)
void DrawLineForInsertionPoint(int index, Pen pen, DrawingContext drawingContext)
{
var currentInsertionPoint = insertionPoints[index];
var pos = editor.TextView.GetVisualPosition(new TextViewPosition(currentInsertionPoint.Location), VisualYPosition.LineMiddle);

3
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/InsertionPoint.cs

@ -91,11 +91,12 @@ namespace CSharpBinding.Refactoring @@ -91,11 +91,12 @@ namespace CSharpBinding.Refactoring
int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset;
InsertNewLine (document, LineBefore, ref offset);
int result = offset - insertionOffset;
document.Insert (offset, text);
offset += text.Length;
InsertNewLine (document, LineAfter, ref offset);
return offset;
return result;
}
}

Loading…
Cancel
Save