Skip to content

Instantly share code, notes, and snippets.

@jhoughjr
Last active May 3, 2018 16:58
Show Gist options
  • Save jhoughjr/68f42e47a1104ce8ac8d837d0024cac5 to your computer and use it in GitHub Desktop.
Save jhoughjr/68f42e47a1104ce8ac8d837d0024cac5 to your computer and use it in GitHub Desktop.
func focusEditor() {
let loc = CGPoint(x: (textView!.frame.origin.x + (textView!.frame.size.width / 2)),
y: (textView!.frame.origin.y + (textView!.frame.size.height / 2)))
let realLoc = textView!.convert(loc,
to: nil)
let e = NSEvent.mouseEvent(with: .leftMouseDown,
location: realLoc,
modifierFlags: [],
timestamp:ProcessInfo.processInfo.systemUptime ,
windowNumber: textView!.window!.windowNumber,
context: nil,
eventNumber: 0,
clickCount: 1,
pressure: 0.0)
textView?.mouseDown(with: e!)
// let f = WKUserScript(source: "quill.focus();",
// injectionTime: .atDocumentEnd,
// forMainFrameOnly: false)
// textView?.evaluateJavaScript(f.source,
// completionHandler: { (obj, err) in
// SwiftyBeaver.debug("focued")
// })
}
@jhoughjr
Copy link
Author

jhoughjr commented May 3, 2018

(lldb) po err!
Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=TypeError: null is not an object (evaluating 'document.getElementById('editor').click'), WKJavaScriptExceptionColumnNumber=34, WKJavaScriptExceptionSourceURL=undefined, NSLocalizedDescription=A JavaScript exception occurred}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment