Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 96fdb81

Browse files
fix #526: InsertWithCursor broken in Create Enum refactoring - Enum member is added properly
1 parent 569e086 commit 96fdb81

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

  • src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,31 @@ void InsertWithCursorOnLayer(EditorScript currentScript, InsertionCursorLayer la
173173
args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) {
174174
args.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
175175
}
176+
177+
var insertionPoint = args.InsertionPoint;
178+
if (nodes.All(n => n is EnumMemberDeclaration)) {
179+
insertionPoint.LineAfter = NewLineInsertion.Eol;
180+
insertionPoint.LineBefore = NewLineInsertion.None;
181+
}
176182

177-
int offset = currentScript.GetCurrentOffset(args.InsertionPoint.Location);
183+
int offset = currentScript.GetCurrentOffset(insertionPoint.Location);
178184
int indentLevel = currentScript.GetIndentLevelAt(Math.Max(0, offset - 1));
179185

180186
foreach (var node in nodes.Reverse()) {
181187
var output = currentScript.OutputNode(indentLevel, node);
182188
var text = output.Text;
183-
var insertionPoint = args.InsertionPoint;
184189
if (node is EnumMemberDeclaration) {
185-
insertionPoint.LineAfter = NewLineInsertion.Eol;
186-
insertionPoint.LineBefore = NewLineInsertion.None;
187-
if (args.InsertionPoint != layer.InsertionPoints.Last()) {
190+
if (insertionPoint != layer.InsertionPoints.Last()) {
188191
text += ",";
192+
} else {
193+
var parentEnum = currentScript.context.RootNode.GetNodeAt(insertionPoint.Location, n => (n is TypeDeclaration) && ((TypeDeclaration)n).ClassType == ClassType.Enum) as TypeDeclaration;
194+
if (parentEnum != null) {
195+
var lastMember = parentEnum.Members.LastOrDefault();
196+
if (lastMember != null) {
197+
var segment = currentScript.GetSegment(lastMember);
198+
currentScript.InsertText(segment.EndOffset, ",");
199+
}
200+
}
189201
}
190202
}
191203
int delta = insertionPoint.Insert(target, text);

0 commit comments

Comments
 (0)