-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xcode 8.3.3中格式化选中的多行代码,最后一行没有对齐 #107
Comments
使用 XAlign.1.0.dmg 在 Xcode 9 beta 版本下,同样有这问题;请修复下。 |
IDE: Xcode 9 & 9.0.1 |
How to fix "The last line" problem.
+ (void)autoAlign:(XCSourceEditorCommandInvocation *)invocation
{
NSMutableArray * selections = [NSMutableArray array];
for ( XCSourceTextRange *range in invocation.buffer.selections )
{
for ( NSInteger i = range.start.line; i < range.end.line ; i++)
{
[selections addObject:invocation.buffer.lines[i]];
}
}
NSString * selectedString = [selections componentsJoinedByString:@""];
NSArray * patternGroup = [XAlignPatternManager patternGroupMatchWithString:selectedString];
if ( !patternGroup )
return;
NSString * alignedString = [selectedString stringByAligningWithPatterns:patternGroup];
NSArray * result = [alignedString componentsSeparatedByString:@"\n"];
for ( XCSourceTextRange *range in invocation.buffer.selections )
{
for ( NSInteger i = range.start.line, j=0; i < range.end.line ; i++, j++ )
{
invocation.buffer.lines[i] = result[j];
}
}
} The new code. + (void)autoAlign:(XCSourceEditorCommandInvocation *)invocation
{
NSMutableArray * selections = [NSMutableArray array];
for ( XCSourceTextRange * range in invocation.buffer.selections )
{
for ( NSInteger i = range.start.line; i < range.end.line + 1 ; i++)
{
if ( i <= invocation.buffer.lines.count )
{
[selections addObject:invocation.buffer.lines[i]];
}
}
}
NSString * selectedString = [selections componentsJoinedByString:@""];
NSArray * patternGroup = [XAlignPatternManager patternGroupMatchWithString:selectedString];
if ( !patternGroup )
return;
NSString * alignedString = [selectedString stringByAligningWithPatterns:patternGroup];
NSArray * result = [alignedString componentsSeparatedByString:@"\n"];
for ( XCSourceTextRange *range in invocation.buffer.selections )
{
for ( NSInteger i = range.start.line, j=0; i < range.end.line + 1 ; i++, j++ )
{
if ( i <= invocation.buffer.lines.count )
{
invocation.buffer.lines[i] = result[j];
}
}
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IDE: Xcode 8.3.3
OS: 10.12.5
多行赋值语句全部选中之后,使用快捷键对齐代码的时候
最后一行没有按照"="号对其
The text was updated successfully, but these errors were encountered: