From 01fc57e3078ddf6514ad6c618cd45f30ba70fd6e Mon Sep 17 00:00:00 2001 From: Mike Fikes Date: Sat, 18 May 2019 10:18:33 -0400 Subject: [PATCH] It is possible to auto-eval on enter before engine ready Fixes #54 --- Replete/ViewController.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Replete/ViewController.swift b/Replete/ViewController.swift index 4b6b867..03ed848 100644 --- a/Replete/ViewController.swift +++ b/Replete/ViewController.swift @@ -67,11 +67,8 @@ class ViewController: NSViewController { NSLog("Initializing..."); DispatchQueue.global(qos: .background).async { self.ctx.initializeJavaScriptEnvironment() - DispatchQueue.main.async { - // mark ready - NSLog("Ready"); - self.initialized = true; - } + self.initialized = true; + NSLog("Ready"); } } @@ -90,6 +87,9 @@ class ViewController: NSViewController { // Automatically evaluate if enter happens to be pressed when // cursor is positioned at the end of the text. if (enterPressed && affectedCharRange.location == textView.string.count) { + while (!self.initialized) { + Thread.sleep(forTimeInterval: 0.1); + } enterPressed = false self.evaluate(textView) return false;