2016-12-21 09:33:39 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
import RxSwift
|
|
|
|
import PureLayout
|
|
|
|
import CocoaMarkdown
|
2016-12-27 09:26:31 +03:00
|
|
|
import WebKit
|
2016-12-21 09:33:39 +03:00
|
|
|
|
2016-12-27 09:26:31 +03:00
|
|
|
fileprivate class WebviewMessageHandler: NSObject, WKScriptMessageHandler {
|
|
|
|
|
|
|
|
enum Action {
|
|
|
|
|
|
|
|
case scroll(lineBegin: Int, columnBegin: Int, lineEnd: Int, columnEnd: Int)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate let flow: EmbeddableComponent
|
|
|
|
|
|
|
|
override init() {
|
|
|
|
flow = EmbeddableComponent(source: Observable.empty())
|
|
|
|
super.init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func userContentController(_: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
|
|
guard let msgBody = message.body as? [String: Int] else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let lineBegin = msgBody["lineBegin"],
|
|
|
|
let columnBegin = msgBody["columnBegin"],
|
|
|
|
let lineEnd = msgBody["lineEnd"],
|
|
|
|
let columnEnd = msgBody["columnEnd"]
|
|
|
|
else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
flow.publish(event: Action.scroll(lineBegin: lineBegin, columnBegin: columnBegin,
|
|
|
|
lineEnd: lineEnd, columnEnd: columnEnd))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
|
|
|
|
|
2017-01-01 09:52:02 +03:00
|
|
|
static let identifier = "com.qvacua.vimr.tool.preview.markdown"
|
|
|
|
static func prefData(from dict: [String: Any]) -> StandardPrefData? {
|
|
|
|
return PrefData(dict: dict)
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PrefData: StandardPrefData {
|
|
|
|
|
|
|
|
fileprivate static let identifier = "identifier"
|
|
|
|
fileprivate static let isForwardSearchAutomatically = "is-forward-search-automatically"
|
|
|
|
fileprivate static let isReverseSearchAutomatically = "is-reverse-search-automatically"
|
2017-01-03 19:32:13 +03:00
|
|
|
fileprivate static let isRefreshOnWrite = "is-refresh-on-write"
|
2017-01-01 09:52:02 +03:00
|
|
|
|
2017-01-03 19:32:13 +03:00
|
|
|
static let `default` = PrefData(isForwardSearchAutomatically: false,
|
|
|
|
isReverseSearchAutomatically: false,
|
|
|
|
isRefreshOnWrite: true)
|
2017-01-01 09:52:02 +03:00
|
|
|
|
|
|
|
var isForwardSearchAutomatically: Bool
|
|
|
|
var isReverseSearchAutomatically: Bool
|
2017-01-03 19:32:13 +03:00
|
|
|
var isRefreshOnWrite: Bool
|
2017-01-01 09:52:02 +03:00
|
|
|
|
2017-01-03 19:32:13 +03:00
|
|
|
init(isForwardSearchAutomatically: Bool, isReverseSearchAutomatically: Bool, isRefreshOnWrite: Bool) {
|
2017-01-01 09:52:02 +03:00
|
|
|
self.isForwardSearchAutomatically = isForwardSearchAutomatically
|
|
|
|
self.isReverseSearchAutomatically = isReverseSearchAutomatically
|
2017-01-03 19:32:13 +03:00
|
|
|
self.isRefreshOnWrite = isRefreshOnWrite
|
2017-01-01 09:52:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
init?(dict: [String: Any]) {
|
|
|
|
guard PrefUtils.string(from: dict, for: PrefData.identifier) == MarkdownRenderer.identifier else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let isForward = PrefUtils.bool(from: dict, for: PrefData.isForwardSearchAutomatically) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let isReverse = PrefUtils.bool(from: dict, for: PrefData.isReverseSearchAutomatically) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-01-03 19:32:13 +03:00
|
|
|
guard let isRefreshOnWrite = PrefUtils.bool(from: dict, for: PrefData.isRefreshOnWrite) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
self.init(isForwardSearchAutomatically: isForward,
|
|
|
|
isReverseSearchAutomatically: isReverse,
|
|
|
|
isRefreshOnWrite: isRefreshOnWrite)
|
2017-01-01 09:52:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func dict() -> [String: Any] {
|
|
|
|
return [
|
|
|
|
PrefData.identifier: MarkdownRenderer.identifier,
|
|
|
|
PrefData.isForwardSearchAutomatically: self.isForwardSearchAutomatically,
|
|
|
|
PrefData.isReverseSearchAutomatically: self.isReverseSearchAutomatically,
|
2017-01-03 19:32:13 +03:00
|
|
|
PrefData.isRefreshOnWrite: self.isRefreshOnWrite,
|
2017-01-01 09:52:02 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
fileprivate let flow: EmbeddableComponent
|
2017-01-06 16:41:19 +03:00
|
|
|
fileprivate let scrollFlow: EmbeddableComponent
|
2016-12-23 14:15:26 +03:00
|
|
|
|
2016-12-26 11:36:23 +03:00
|
|
|
fileprivate let scheduler = ConcurrentDispatchQueueScheduler(qos: .userInitiated)
|
2016-12-26 11:04:03 +03:00
|
|
|
fileprivate let baseUrl = Bundle.main.resourceURL!.appendingPathComponent("markdown")
|
|
|
|
fileprivate let extensions = Set(["md", "markdown", ])
|
|
|
|
fileprivate let template: String
|
|
|
|
|
2016-12-27 09:26:31 +03:00
|
|
|
fileprivate let userContentController = WKUserContentController()
|
|
|
|
fileprivate let webviewMessageHandler = WebviewMessageHandler()
|
|
|
|
|
2017-01-01 09:52:02 +03:00
|
|
|
fileprivate var isForwardSearchAutomatically = false
|
|
|
|
fileprivate var isReverseSearchAutomatically = false
|
2017-01-03 19:32:13 +03:00
|
|
|
fileprivate var isRefreshOnWrite = true
|
2017-01-01 09:52:02 +03:00
|
|
|
|
2017-01-06 19:41:19 +03:00
|
|
|
fileprivate let automaticForwardMenuItem = NSMenuItem(title: "Automatic Forward Search",
|
|
|
|
action: nil,
|
|
|
|
keyEquivalent: "")
|
|
|
|
fileprivate let automaticReverseMenuItem = NSMenuItem(title: "Automatic Reverse Search",
|
|
|
|
action: nil,
|
|
|
|
keyEquivalent: "")
|
|
|
|
fileprivate let refreshOnWriteMenuItem = NSMenuItem(title: "Refresh on Write", action: nil, keyEquivalent: "")
|
|
|
|
|
2016-12-27 09:26:31 +03:00
|
|
|
fileprivate let webview: WKWebView
|
|
|
|
|
2017-01-04 22:53:28 +03:00
|
|
|
fileprivate var currentPreviewPosition = Position(row: 0, column: 0)
|
2017-01-04 20:38:52 +03:00
|
|
|
weak fileprivate var neoVimInfoProvider: NeoVimInfoProvider?
|
|
|
|
|
2017-01-01 09:52:02 +03:00
|
|
|
let identifier: String = MarkdownRenderer.identifier
|
|
|
|
var prefData: StandardPrefData? {
|
|
|
|
return PrefData(isForwardSearchAutomatically: self.isForwardSearchAutomatically,
|
2017-01-03 19:32:13 +03:00
|
|
|
isReverseSearchAutomatically: self.isReverseSearchAutomatically,
|
|
|
|
isRefreshOnWrite: self.isRefreshOnWrite)
|
2017-01-01 09:52:02 +03:00
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
var sink: Observable<Any> {
|
|
|
|
return self.flow.sink
|
|
|
|
}
|
|
|
|
|
2017-01-06 16:41:19 +03:00
|
|
|
var scrollSink: Observable<Any> {
|
|
|
|
return self.scrollFlow.sink
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
let toolbar: NSView? = NSView(forAutoLayout: ())
|
|
|
|
let menuItems: [NSMenuItem]?
|
|
|
|
|
2017-01-04 20:38:52 +03:00
|
|
|
init(source: Observable<Any>, scrollSource: Observable<Any>, neoVimInfoProvider: NeoVimInfoProvider, initialData: PrefData) {
|
2016-12-26 11:04:03 +03:00
|
|
|
guard let templateUrl = Bundle.main.url(forResource: "template",
|
|
|
|
withExtension: "html",
|
|
|
|
subdirectory: "markdown")
|
|
|
|
else {
|
|
|
|
preconditionFailure("ERROR Cannot load markdown template")
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let template = try? String(contentsOf: templateUrl) else {
|
|
|
|
preconditionFailure("ERROR Cannot load markdown template")
|
|
|
|
}
|
|
|
|
|
2017-01-04 20:38:52 +03:00
|
|
|
self.neoVimInfoProvider = neoVimInfoProvider
|
|
|
|
|
2016-12-26 11:04:03 +03:00
|
|
|
self.template = template
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
self.flow = EmbeddableComponent(source: source)
|
2017-01-06 16:41:19 +03:00
|
|
|
self.scrollFlow = EmbeddableComponent(source: scrollSource)
|
2016-12-30 06:32:08 +03:00
|
|
|
|
2016-12-27 09:26:31 +03:00
|
|
|
let configuration = WKWebViewConfiguration()
|
|
|
|
configuration.userContentController = self.userContentController
|
|
|
|
self.webview = WKWebView(frame: .zero, configuration: configuration)
|
|
|
|
self.webview.configureForAutoLayout()
|
|
|
|
|
2017-01-03 19:44:25 +03:00
|
|
|
self.isForwardSearchAutomatically = initialData.isForwardSearchAutomatically
|
|
|
|
self.isReverseSearchAutomatically = initialData.isReverseSearchAutomatically
|
|
|
|
self.isRefreshOnWrite = initialData.isRefreshOnWrite
|
|
|
|
|
2017-01-03 19:48:21 +03:00
|
|
|
let refreshMenuItem = NSMenuItem(title: "Refresh Now", action: nil, keyEquivalent: "")
|
2016-12-30 06:32:08 +03:00
|
|
|
let forwardSearchMenuItem = NSMenuItem(title: "Forward Search", action: nil, keyEquivalent: "")
|
|
|
|
let reverseSearchMenuItem = NSMenuItem(title: "Reverse Search", action: nil, keyEquivalent: "")
|
2016-12-27 09:26:31 +03:00
|
|
|
|
2017-01-06 19:41:19 +03:00
|
|
|
let automaticForward = self.automaticForwardMenuItem
|
|
|
|
let automaticReverse = self.automaticReverseMenuItem
|
|
|
|
let refreshOnWrite = self.refreshOnWriteMenuItem
|
|
|
|
|
|
|
|
automaticForward.boolState = self.isForwardSearchAutomatically
|
|
|
|
automaticReverse.boolState = self.isReverseSearchAutomatically
|
|
|
|
refreshOnWrite.boolState = self.isRefreshOnWrite
|
2017-01-03 19:44:25 +03:00
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
self.menuItems = [
|
2017-01-03 19:48:21 +03:00
|
|
|
refreshMenuItem,
|
2016-12-30 06:32:08 +03:00
|
|
|
forwardSearchMenuItem,
|
|
|
|
reverseSearchMenuItem,
|
|
|
|
NSMenuItem.separator(),
|
2017-01-06 19:41:19 +03:00
|
|
|
automaticForward,
|
|
|
|
automaticReverse,
|
2017-01-03 19:32:13 +03:00
|
|
|
NSMenuItem.separator(),
|
2017-01-06 19:41:19 +03:00
|
|
|
refreshOnWrite,
|
2016-12-30 06:32:08 +03:00
|
|
|
]
|
2016-12-27 09:26:31 +03:00
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
super.init()
|
2016-12-26 11:04:03 +03:00
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
self.initCustomUiElements()
|
|
|
|
|
2017-01-03 19:48:21 +03:00
|
|
|
refreshMenuItem.target = self
|
|
|
|
refreshMenuItem.action = #selector(MarkdownRenderer.refreshNowAction)
|
2016-12-30 06:32:08 +03:00
|
|
|
forwardSearchMenuItem.target = self
|
|
|
|
forwardSearchMenuItem.action = #selector(MarkdownRenderer.forwardSearchAction)
|
|
|
|
reverseSearchMenuItem.target = self
|
|
|
|
reverseSearchMenuItem.action = #selector(MarkdownRenderer.reverseSearchAction)
|
2017-01-06 19:41:19 +03:00
|
|
|
automaticForward.target = self
|
|
|
|
automaticForward.action = #selector(MarkdownRenderer.automaticForwardSearchAction)
|
|
|
|
automaticReverse.target = self
|
|
|
|
automaticReverse.action = #selector(MarkdownRenderer.automaticReverseSearchAction)
|
|
|
|
refreshOnWrite.target = self
|
|
|
|
refreshOnWrite.action = #selector(MarkdownRenderer.refreshOnWriteAction)
|
2016-12-30 06:32:08 +03:00
|
|
|
|
2017-01-06 16:41:19 +03:00
|
|
|
self.flow.set(subscription: self.subscription)
|
|
|
|
self.scrollFlow.set(subscription: self.scrollSubscription)
|
2017-01-04 22:32:56 +03:00
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
self.addReactions()
|
|
|
|
self.userContentController.add(webviewMessageHandler, name: "com_vimr_preview_markdown")
|
2016-12-26 11:04:03 +03:00
|
|
|
}
|
2016-12-23 14:15:26 +03:00
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
func canRender(fileExtension: String) -> Bool {
|
2016-12-23 14:15:26 +03:00
|
|
|
return extensions.contains(fileExtension)
|
|
|
|
}
|
2016-12-21 09:33:39 +03:00
|
|
|
|
2017-01-06 16:41:19 +03:00
|
|
|
fileprivate func scrollSubscription(source: Observable<Any>) -> Disposable {
|
|
|
|
return source
|
|
|
|
.throttle(1, latest: true, scheduler: self.scheduler)
|
|
|
|
.filter { $0 is MainWindowComponent.ScrollAction }
|
|
|
|
.subscribe(onNext: { [unowned self] action in
|
2017-01-06 18:51:28 +03:00
|
|
|
// NSLog("neovim scrolled to \(self.neoVimInfoProvider?.currentLine()) x \(self.neoVimInfoProvider?.currentColumn())")
|
|
|
|
guard self.isForwardSearchAutomatically else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
self.forwardSearchAction(nil)
|
2017-01-06 16:41:19 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
fileprivate func subscription(source: Observable<Any>) -> Disposable {
|
2016-12-21 09:33:39 +03:00
|
|
|
return source
|
2016-12-26 11:36:23 +03:00
|
|
|
.observeOn(self.scheduler)
|
2016-12-27 11:32:55 +03:00
|
|
|
.mapOmittingNil { action in
|
|
|
|
|
2016-12-21 09:33:39 +03:00
|
|
|
switch action {
|
2016-12-27 11:32:55 +03:00
|
|
|
case let PreviewComponent.Action.automaticRefresh(url):
|
2017-01-03 19:32:13 +03:00
|
|
|
guard self.isRefreshOnWrite else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-23 14:15:26 +03:00
|
|
|
return url
|
2016-12-27 11:32:55 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
|
2016-12-21 09:33:39 +03:00
|
|
|
}
|
2016-12-23 14:15:26 +03:00
|
|
|
}
|
2017-01-01 09:52:02 +03:00
|
|
|
.filter { self.canRender(fileExtension: $0.pathExtension) }
|
2016-12-23 14:15:26 +03:00
|
|
|
.subscribe(onNext: { [unowned self] url in self.render(from: url) })
|
2016-12-21 09:33:39 +03:00
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
fileprivate func initCustomUiElements() {
|
2017-01-03 19:06:55 +03:00
|
|
|
let refresh = NSButton(forAutoLayout: ())
|
|
|
|
InnerToolBar.configureToStandardIconButton(button: refresh, iconName: .refresh)
|
|
|
|
refresh.toolTip = "Refresh Now"
|
|
|
|
refresh.target = self
|
2017-01-03 19:48:21 +03:00
|
|
|
refresh.action = #selector(MarkdownRenderer.refreshNowAction)
|
2017-01-03 19:06:55 +03:00
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
let forward = NSButton(forAutoLayout: ())
|
|
|
|
InnerToolBar.configureToStandardIconButton(button: forward, iconName: .chevronCircleRight)
|
|
|
|
forward.toolTip = "Forward Search"
|
|
|
|
forward.target = self
|
|
|
|
forward.action = #selector(MarkdownRenderer.forwardSearchAction)
|
|
|
|
|
|
|
|
let reverse = NSButton(forAutoLayout: ())
|
|
|
|
InnerToolBar.configureToStandardIconButton(button: reverse, iconName: .chevronCircleLeft)
|
|
|
|
reverse.toolTip = "Reverse Search"
|
|
|
|
reverse.target = self
|
|
|
|
reverse.action = #selector(MarkdownRenderer.reverseSearchAction)
|
|
|
|
|
|
|
|
self.toolbar?.addSubview(forward)
|
|
|
|
self.toolbar?.addSubview(reverse)
|
2017-01-03 19:06:55 +03:00
|
|
|
self.toolbar?.addSubview(refresh)
|
2016-12-30 06:32:08 +03:00
|
|
|
|
|
|
|
forward.autoPinEdge(toSuperviewEdge: .top)
|
|
|
|
forward.autoPinEdge(toSuperviewEdge: .right)
|
|
|
|
|
|
|
|
reverse.autoPinEdge(toSuperviewEdge: .top)
|
|
|
|
reverse.autoPinEdge(.right, to: .left, of: forward)
|
2017-01-03 19:06:55 +03:00
|
|
|
|
|
|
|
refresh.autoPinEdge(toSuperviewEdge: .top)
|
|
|
|
refresh.autoPinEdge(.right, to: .left, of: reverse)
|
2016-12-30 06:32:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate func addReactions() {
|
|
|
|
self.webviewMessageHandler.flow.sink
|
|
|
|
.filter { $0 is WebviewMessageHandler.Action }
|
|
|
|
.map { $0 as! WebviewMessageHandler.Action }
|
|
|
|
.subscribe(onNext: { [weak self] action in
|
2017-01-06 18:51:28 +03:00
|
|
|
guard self?.isReverseSearchAutomatically == true else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
switch action {
|
|
|
|
case let .scroll(lineBegin, columnBegin, _, _):
|
2017-01-04 22:53:28 +03:00
|
|
|
self?.currentPreviewPosition = Position(row: lineBegin, column: columnBegin)
|
2017-01-06 18:51:28 +03:00
|
|
|
self?.flow.publish(
|
|
|
|
event: PreviewRendererAction.reverseSearch(to: Position(row: lineBegin, column: columnBegin))
|
2017-01-06 16:41:19 +03:00
|
|
|
)
|
2016-12-30 06:32:08 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.addDisposableTo(self.flow.disposeBag)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate func filledTemplate(body: String, title: String) -> String {
|
|
|
|
return self.template
|
|
|
|
.replacingOccurrences(of: "{{ title }}", with: title)
|
|
|
|
.replacingOccurrences(of: "{{ body }}", with: body)
|
|
|
|
}
|
|
|
|
|
2016-12-21 09:33:39 +03:00
|
|
|
fileprivate func render(from url: URL) {
|
2016-12-27 09:26:31 +03:00
|
|
|
|
2016-12-26 11:04:03 +03:00
|
|
|
NSLog("\(#function): \(url)")
|
|
|
|
|
2016-12-26 12:17:01 +03:00
|
|
|
let doc = CMDocument(contentsOfFile: url.path, options: .sourcepos)
|
2016-12-21 09:33:39 +03:00
|
|
|
let renderer = CMHTMLRenderer(document: doc)
|
|
|
|
|
2016-12-26 11:04:03 +03:00
|
|
|
guard let body = renderer?.render() else {
|
2016-12-30 06:32:08 +03:00
|
|
|
self.flow.publish(event: PreviewRendererAction.error)
|
2016-12-21 09:33:39 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-26 11:04:03 +03:00
|
|
|
let html = filledTemplate(body: body, title: url.lastPathComponent)
|
2016-12-27 09:26:31 +03:00
|
|
|
self.webview.loadHTMLString(html, baseURL: self.baseUrl)
|
2016-12-26 11:04:03 +03:00
|
|
|
|
|
|
|
try? html.write(toFile: "/tmp/markdown-preview.html", atomically: false, encoding: .utf8)
|
2016-12-30 06:32:08 +03:00
|
|
|
self.flow.publish(event: PreviewRendererAction.view(renderer: self, view: self.webview))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Actions
|
|
|
|
extension MarkdownRenderer {
|
|
|
|
|
2017-01-03 19:48:21 +03:00
|
|
|
func refreshNowAction(_: Any?) {
|
2017-01-03 19:06:55 +03:00
|
|
|
NSLog("\(#function)")
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:32:08 +03:00
|
|
|
func forwardSearchAction(_: Any?) {
|
2017-01-06 18:06:07 +03:00
|
|
|
guard let row = self.neoVimInfoProvider?.currentLine(),
|
|
|
|
let column = self.neoVimInfoProvider?.currentColumn()
|
|
|
|
else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// NSLog("\(#function) for \(row) x \(column)")
|
|
|
|
self.webview.evaluateJavaScript("scrollToPosition(\(row), \(column));")
|
2016-12-30 06:32:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func reverseSearchAction(_: Any?) {
|
2017-01-06 18:39:03 +03:00
|
|
|
self.webview.evaluateJavaScript("currentPosition();") { resultObj, error in
|
|
|
|
guard let resultDict = resultObj as? [String: Int] else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let lineBegin = resultDict["lineBegin"], let columnBegin = resultDict["columnBegin"] else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
self.flow.publish(event: PreviewRendererAction.reverseSearch(to: Position(row: lineBegin, column: columnBegin)))
|
|
|
|
}
|
|
|
|
// NSLog("\(#function) for \(self.currentPreviewPosition)")
|
2016-12-30 06:32:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func automaticForwardSearchAction(_: Any?) {
|
2017-01-01 09:52:02 +03:00
|
|
|
self.isForwardSearchAutomatically = !self.isForwardSearchAutomatically
|
2016-12-30 06:32:08 +03:00
|
|
|
NSLog("\(#function)")
|
|
|
|
}
|
|
|
|
|
|
|
|
func automaticReverseSearchAction(_: Any?) {
|
2017-01-01 09:52:02 +03:00
|
|
|
self.isReverseSearchAutomatically = !self.isReverseSearchAutomatically
|
2016-12-30 06:32:08 +03:00
|
|
|
NSLog("\(#function)")
|
2016-12-21 09:33:39 +03:00
|
|
|
}
|
2017-01-03 19:32:13 +03:00
|
|
|
|
|
|
|
func refreshOnWriteAction(_: Any?) {
|
|
|
|
self.isRefreshOnWrite = !self.isRefreshOnWrite
|
|
|
|
NSLog("\(#function)")
|
|
|
|
}
|
2016-12-21 09:33:39 +03:00
|
|
|
}
|