Skip to content

Commit

Permalink
Redbox: skip column number if it is 0
Browse files Browse the repository at this point in the history
Summary:
Format before:
```
methodName
file_name.js @ 42:0
```

Format after
```
methodName
file_name.js:42
```

Reviewed By: javache

Differential Revision: D3350320

fbshipit-source-id: 456deb66bd34deb24bf8b8aa958883bdf4f99129
  • Loading branch information
frantic authored and Facebook Github Bot 9 committed May 27, 2016
1 parent 1623e34 commit 0656b96
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions React/Modules/RCTRedBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (instancetype)initWithFrame:(CGRect)frame
[copyButton setTitleColor:[UIColor colorWithWhite:1 alpha:0.5] forState:UIControlStateNormal];
[copyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[copyButton addTarget:self action:@selector(copyStack) forControlEvents:UIControlEventTouchUpInside];

CGFloat buttonWidth = self.bounds.size.width / 3;
dismissButton.frame = CGRectMake(0, self.bounds.size.height - buttonHeight, buttonWidth, buttonHeight);
reloadButton.frame = CGRectMake(buttonWidth, self.bounds.size.height - buttonHeight, buttonWidth, buttonHeight);
Expand Down Expand Up @@ -147,30 +147,39 @@ - (void)reload
- (void)copyStack
{
NSMutableString *fullStackTrace;

if (_lastErrorMessage != nil) {
fullStackTrace = [_lastErrorMessage mutableCopy];
[fullStackTrace appendString:@"\n\n"];
}
else {
fullStackTrace = [NSMutableString string];
}

for (NSDictionary *stackFrame in _lastStackTrace) {
[fullStackTrace appendString:[NSString stringWithFormat:@"%@\n", stackFrame[@"methodName"]]];
if (stackFrame[@"file"]) {
NSString *lineInfo = [NSString stringWithFormat:@" %@ @ %zd:%zd\n",
[stackFrame[@"file"] lastPathComponent],
[stackFrame[@"lineNumber"] integerValue],
[stackFrame[@"column"] integerValue]];
[fullStackTrace appendString:lineInfo];
[fullStackTrace appendFormat:@" %@\n", [self formatFrameSource:stackFrame]];
}
}

UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:fullStackTrace];
}

- (NSString *)formatFrameSource:(NSDictionary *)stackFrame
{
NSString *lineInfo = [NSString stringWithFormat:@"%@:%zd",
[stackFrame[@"file"] lastPathComponent],
[stackFrame[@"lineNumber"] integerValue]];

NSInteger column = [stackFrame[@"column"] integerValue];
if (column != 0) {
lineInfo = [lineInfo stringByAppendingFormat:@":%zd", column];
}
return lineInfo;
}

#pragma mark - TableView

- (NSInteger)numberOfSectionsInTableView:(__unused UITableView *)tableView
Expand Down Expand Up @@ -231,10 +240,7 @@ - (UITableViewCell *)reuseCell:(UITableViewCell *)cell forStackFrame:(NSDictiona

cell.textLabel.text = stackFrame[@"methodName"];
if (stackFrame[@"file"]) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ @ %zd:%zd",
[stackFrame[@"file"] lastPathComponent],
[stackFrame[@"lineNumber"] integerValue],
[stackFrame[@"column"] integerValue]];
cell.detailTextLabel.text = [self formatFrameSource:stackFrame];
} else {
cell.detailTextLabel.text = @"";
}
Expand Down

0 comments on commit 0656b96

Please sign in to comment.