Commits

Anonymous committed 0cff1bc

Make tabs work in diffs.

Comments (0)

Files changed (1)

Source/SourceHighlighting.m

     if (!code) return nil;
     NSFont *font = [NSFont fontWithName: @"Monaco" size: 10.0f];
     NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
+    CGFloat characterWidth = [font maximumAdvancement].width;
+    NSMutableArray *tabStops = [[NSMutableArray alloc] initWithCapacity:99];
+    NSUInteger tabWidth = 8;
+    for (NSUInteger tabStopIndex = 1; tabStopIndex < 100; tabStopIndex++) {
+	[tabStops addObject:[[NSTextTab alloc] initWithType:NSLeftTabStopType
+						   location:((tabStopIndex * tabWidth) + 1) * characterWidth]];
+    }
+    paraStyle.tabStops = tabStops;
     paraStyle.lineBreakMode = NSLineBreakByClipping;
     NSDictionary *attrs = $dict({NSFontAttributeName, font},
                                 {NSParagraphStyleAttributeName, paraStyle});