diff --git a/VimR/HtmlPreviewTool.swift b/VimR/HtmlPreviewTool.swift
index c732d8e9..c9208f05 100644
--- a/VimR/HtmlPreviewTool.swift
+++ b/VimR/HtmlPreviewTool.swift
@@ -39,6 +39,16 @@ class HtmlPreviewTool: NSView, UiComponent {
source
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [unowned self] state in
+ guard let serverUrl = state.htmlPreview.server else {
+ return
+ }
+
+ if serverUrl.mark == self.mark {
+ return
+ }
+
+ self.mark = serverUrl.mark
+ self.webview.load(URLRequest(url: serverUrl.payload))
})
.addDisposableTo(self.disposeBag)
}
@@ -53,6 +63,8 @@ class HtmlPreviewTool: NSView, UiComponent {
fileprivate let emitter: ActionEmitter
fileprivate let uuid: String
+ fileprivate var mark = Token()
+
fileprivate let webview: WKWebView
fileprivate let disposeBag = DisposeBag()
diff --git a/VimR/HtmlPreviewToolReducer.swift b/VimR/HtmlPreviewToolReducer.swift
index ddc49c76..da67fada 100644
--- a/VimR/HtmlPreviewToolReducer.swift
+++ b/VimR/HtmlPreviewToolReducer.swift
@@ -25,8 +25,9 @@ class HtmlPreviewToolReducer: Reducer {
case let .selectHtmlFile(url):
state.htmlPreview.htmlFile = url
- state.htmlPreview.server = self.baseServerUrl
- .appendingPathComponent("\(uuid)/\(HtmlPreviewToolReducer.basePath)/index.html")
+ state.htmlPreview.server = Marked(
+ self.baseServerUrl .appendingPathComponent("\(uuid)/\(HtmlPreviewToolReducer.basePath)/index.html")
+ )
}
diff --git a/VimR/HttpServerService.swift b/VimR/HttpServerService.swift
index 0813305d..b67ed257 100644
--- a/VimR/HttpServerService.swift
+++ b/VimR/HttpServerService.swift
@@ -44,9 +44,9 @@ extension HttpServerService {
return
}
- let basePath = serverUrl.deletingLastPathComponent().path
+ let basePath = serverUrl.payload.deletingLastPathComponent().path
- self.server.GET[serverUrl.path] = shareFile(htmlFileUrl.path)
+ self.server.GET[serverUrl.payload.path] = shareFile(htmlFileUrl.path)
self.server["\(basePath)/:path"] = shareFilesFromDirectory(htmlFileUrl.parent.path)
}
diff --git a/VimR/States.swift b/VimR/States.swift
index 455b7a81..8f013d2c 100644
--- a/VimR/States.swift
+++ b/VimR/States.swift
@@ -140,7 +140,7 @@ struct HtmlPreviewState {
static let `default` = HtmlPreviewState()
var htmlFile: URL?
- var server: URL?
+ var server: Marked?
}
struct AppearanceState: SerializableState {