Skip to content

Commit 6d8a8f5

Browse files
erwinmazaerwin-CL
authored andcommitted
Remove extraneous empty lines if existing content is only whitespace
1 parent d12ff5f commit 6d8a8f5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

SCXcodeSwitchExpander/DVTTextCompletionController+SCXcodeSwitchExpander.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,21 @@ - (BOOL)tryExpandingSwitchStatement
146146
// Generate the items to insert and insert them at the end
147147
NSMutableString *replacementString = [NSMutableString string];
148148

149-
if([switchContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length == 0 && ![[SCXcodeSwitchExpander sharedSwitchExpander] isSwift]) {
150-
[replacementString appendString:@"\n"];
149+
NSString *trimmedContent = [switchContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
150+
151+
if(trimmedContent.length == 0) {
152+
// remove extraneous empty lines if existing content is only whitespace
153+
if (switchContent.length > 0) {
154+
[textView insertText:@"" replacementRange:switchContentRange];
155+
closingBracketLocation -= switchContent.length;
156+
switchContentRange.length = 0;
157+
[replacementString appendString:@"\n"];
158+
} else {
159+
// keep Swift code compact
160+
if (![[SCXcodeSwitchExpander sharedSwitchExpander] isSwift]) {
161+
[replacementString appendString:@"\n"];
162+
}
163+
}
151164
}
152165

153166
for(IDEIndexSymbol *child in [((IDEIndexContainerSymbol*)symbol).children allObjects]) {

0 commit comments

Comments
 (0)