From b8b58e65f1680f88abc280a72a38e0da949d5187 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 12 Apr 2020 18:12:22 -0400 Subject: [PATCH] Go back to reading the highlight results on the main queue. The lack of a synchronization signal between the background queue and the main thread caused -scrollToLine: to not reliably work. This reverts part of 430306d5729bd5342ebc3132389c63073a8ca2aa. --- Source/BSSourceView.mm | 59 +++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/Source/BSSourceView.mm b/Source/BSSourceView.mm index 287fd9d..db4b006 100644 --- a/Source/BSSourceView.mm +++ b/Source/BSSourceView.mm @@ -226,42 +226,37 @@ NSString* ColorHEXStringINIDirective(NSString* directive, NSColor* color) { }]; [task launch]; - // Start reading the stdout pipe on a background queue. This is separate - // from the terminiationHandler, since a large file could be greater than + // Start reading the stdout pipe immediately. This is separate from the + // terminiationHandler, since a large file could be greater than // the pipe buffer. - dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ - NSMutableAttributedString* source; - NSData* data = [[outPipe fileHandleForReading] readDataToEndOfFile]; - if (data.length) { - source = [[NSMutableAttributedString alloc] initWithHTML:data - options:@{ NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding) } - documentAttributes:nil]; - - // PHP uses   in the highlighted output, which should be converted - // back to normal spaces. - NSMutableString* stringData = [source mutableString]; - [stringData replaceOccurrencesOfString:@"\u00A0" withString:@" " options:0 range:NSMakeRange(0, stringData.length)]; - - // Override the default font from Courier. - [source addAttributes:@{ NSFontAttributeName : [[self class] sourceFont] } - range:NSMakeRange(0, source.length)]; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - if (source) { - [[self->textView_ textStorage] setAttributedString:source]; - } else { - [self setPlainTextStringFromFile:filePath]; - } + NSMutableAttributedString* source; + NSData* data = [[outPipe fileHandleForReading] readDataToEndOfFile]; + if (data.length) { + source = [[NSMutableAttributedString alloc] initWithHTML:data + options:@{ NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding) } + documentAttributes:nil]; + + // PHP uses   in the highlighted output, which should be converted + // back to normal spaces. + NSMutableString* stringData = [source mutableString]; + [stringData replaceOccurrencesOfString:@"\u00A0" withString:@" " options:0 range:NSMakeRange(0, stringData.length)]; + + // Override the default font from Courier. + [source addAttributes:@{ NSFontAttributeName : [[self class] sourceFont] } + range:NSMakeRange(0, source.length)]; + } - [self->ruler_ performLayout]; + if (source) { + [[textView_ textStorage] setAttributedString:source]; + } else { + [self setPlainTextStringFromFile:filePath]; + } - [self scrollToLine:self->markedLine_]; + [ruler_ performLayout]; - if (handler) - handler(); - }); - }); + if (handler) { + handler(); + } } @catch (NSException* exception) { // If the PHP executable is not available then the NSTask will throw an exception NSLog(@"Failed to highlight file: %@", exception); -- 2.22.5