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
args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) { args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) {
args.InsertionPoint.LineAfter = NewLineInsertion.BlankLine; 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 output = currentScript.OutputNode(indentLevel, node);
var offset = target.GetOffset(args.InsertionPoint.Location); int delta = args.InsertionPoint.Insert(target, output.Text);
var delta = args.InsertionPoint.Insert(target, output.Text);
output.RegisterTrackedSegments(currentScript, delta + offset); output.RegisterTrackedSegments(currentScript, delta + offset);
} }
currentScript.FormatText(nodes);
tcs.SetResult(currentScript); tcs.SetResult(currentScript);
} }
layer.Dispose(); layer.Dispose();
@ -310,14 +313,14 @@ namespace CSharpBinding.Refactoring
protected override void OnRender(DrawingContext drawingContext) protected override void OnRender(DrawingContext drawingContext)
{ {
DrawLineForInserionPoint(CurrentInsertionPoint, markerPen, drawingContext); DrawLineForInsertionPoint(CurrentInsertionPoint, markerPen, drawingContext);
if (insertionPointNextToMouse > -1 && insertionPointNextToMouse != CurrentInsertionPoint) if (insertionPointNextToMouse > -1 && insertionPointNextToMouse != CurrentInsertionPoint)
DrawLineForInserionPoint(insertionPointNextToMouse, tempMarkerPen, drawingContext); DrawLineForInsertionPoint(insertionPointNextToMouse, tempMarkerPen, drawingContext);
SetGroupBoxPosition(); // HACK SetGroupBoxPosition(); // HACK
} }
void DrawLineForInserionPoint(int index, Pen pen, DrawingContext drawingContext) void DrawLineForInsertionPoint(int index, Pen pen, DrawingContext drawingContext)
{ {
var currentInsertionPoint = insertionPoints[index]; var currentInsertionPoint = insertionPoints[index];
var pos = editor.TextView.GetVisualPosition(new TextViewPosition(currentInsertionPoint.Location), VisualYPosition.LineMiddle); 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
int insertionOffset = line.Offset + Location.Column - 1; int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset; offset = insertionOffset;
InsertNewLine (document, LineBefore, ref offset); InsertNewLine (document, LineBefore, ref offset);
int result = offset - insertionOffset;
document.Insert (offset, text); document.Insert (offset, text);
offset += text.Length; offset += text.Length;
InsertNewLine (document, LineAfter, ref offset); InsertNewLine (document, LineAfter, ref offset);
return offset; return result;
} }
} }

Loading…
Cancel
Save