1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00

GH-339 Do manual refresh

This commit is contained in:
Tae Won Ha 2017-01-07 08:30:26 +01:00
parent 91583c5733
commit a3428879af
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 25 additions and 7 deletions

View File

@ -126,6 +126,7 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
fileprivate let webview: WKWebView
fileprivate var currentUrl: URL?
fileprivate var currentPreviewPosition = Position(row: 0, column: 0)
weak fileprivate var neoVimInfoProvider: NeoVimInfoProvider?
@ -231,7 +232,6 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
.throttle(0.5, latest: true, scheduler: self.scheduler)
.filter { $0 is MainWindowComponent.ScrollAction }
.subscribe(onNext: { [unowned self] action in
// NSLog("neovim scrolled to \(self.neoVimInfoProvider?.currentLine()) x \(self.neoVimInfoProvider?.currentColumn())")
guard self.isForwardSearchAutomatically else {
return
}
@ -243,7 +243,7 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
fileprivate func subscription(source: Observable<Any>) -> Disposable {
return source
.observeOn(self.scheduler)
.mapOmittingNil { action in
.mapOmittingNil { (action) -> URL? in
switch action {
case let PreviewComponent.Action.automaticRefresh(url):
@ -258,8 +258,15 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
}
}
.filter { self.canRender(fileExtension: $0.pathExtension) }
.subscribe(onNext: { [unowned self] url in self.render(from: url) })
.subscribe(onNext: { [unowned self] url in
self.currentUrl = url
guard self.canRender(fileExtension: url.pathExtension) else {
return
}
self.render(from: url)
})
}
fileprivate func initCustomUiElements() {
@ -347,7 +354,15 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
extension MarkdownRenderer {
func refreshNowAction(_: Any?) {
NSLog("\(#function)")
guard let url = self.currentUrl else {
return
}
guard self.canRender(fileExtension: url.pathExtension) else {
return
}
self.render(from: url)
}
func forwardSearchAction(_: Any?) {
@ -357,12 +372,10 @@ extension MarkdownRenderer {
return
}
// NSLog("\(#function) for \(row) x \(column)")
self.webview.evaluateJavaScript("scrollToPosition(\(row), \(column));")
}
func reverseSearchAction(_: Any?) {
// NSLog("\(#function) for \(self.currentPreviewPosition)")
self.flow.publish(event: PreviewRendererAction.reverseSearch(to: self.currentPreviewPosition))
}

View File

@ -198,6 +198,11 @@ class PreviewComponent: NSView, ViewComponent, ToolDataHolder {
}
self.currentRenderer = self.renderers.first { $0.canRender(fileExtension: url.pathExtension) }
if self.currentRenderer == nil {
self.currentView = self.webview
self.webview.loadHTMLString(self.previewService.emptyHtml(), baseURL: self.baseUrl)
}
self.flow.publish(event: PreviewComponent.Action.automaticRefresh(url: url))
case let .toggleTool(tool):