Go back to reading the highlight results on the main queue.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 12 Apr 2020 22:12:22 +0000 (18:12 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 12 Apr 2020 22:13:21 +0000 (18:13 -0400)
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

index 287fd9da72a78fe9808770d0227180fbfee7e7bf..db4b006c2196dbe5b83718b55d41a6d3e929d29b 100644 (file)
@@ -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 &nbsp; 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 &nbsp; 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);