Xcode 8.3.3中格式化选中的多行代码,最后一行没有对齐
seigelions opened this issue · 3 comments
seigelions commented
IDE: Xcode 8.3.3
OS: 10.12.5
多行赋值语句全部选中之后,使用快捷键对齐代码的时候
最后一行没有按照"="号对其
KenmuHuang commented
使用 XAlign.1.0.dmg 在 Xcode 9 beta 版本下,同样有这问题;请修复下。
seigelions commented
IDE: Xcode 9 & 9.0.1
OS: 10.12.6
同样有这问题
titman commented
How to fix "The last line" problem.
- Open
XAlign.xcodeproj
- Find and select
SourceEditorCommand.m
file - Find and override these 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 ; 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];
}
}
}
}
- Save and rebuild XAlign.xcodeproj