From 867c06617920d3407926e5868c590a536f411fb4 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 23 Mar 2019 10:42:49 +0100 Subject: [PATCH] Use weak instead of unowned --- VimR/VimR/PreviewTool.swift | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/VimR/VimR/PreviewTool.swift b/VimR/VimR/PreviewTool.swift index 6ff13e83..37e08fd4 100644 --- a/VimR/VimR/PreviewTool.swift +++ b/VimR/VimR/PreviewTool.swift @@ -93,8 +93,7 @@ class PreviewTool: NSView, UiComponent, WKNavigationDelegate { if state.preview.status == .markdown && state.previewTool.isForwardSearchAutomatically - && state.preview.editorPosition.hasDifferentMark(as: self.editorPosition) - { + && state.preview.editorPosition.hasDifferentMark(as: self.editorPosition) { self.forwardSearch(position: state.preview.editorPosition.payload) } @@ -120,10 +119,13 @@ class PreviewTool: NSView, UiComponent, WKNavigationDelegate { self.webviewMessageHandler.source .throttle(0.75, latest: true, scheduler: self.scheduler) - .subscribe(onNext: { [unowned self] (position, scrollTop) in - self.previewPosition = position - self.scrollTop = scrollTop - self.emit(UuidAction(uuid: self.uuid, action: .scroll(to: self.previewPosition))) + .subscribe(onNext: { [weak self] position, scrollTop in + guard let uuid = self?.uuid, + let previewPosition = self?.previewPosition else { return } + + self?.previewPosition = position + self?.scrollTop = scrollTop + self?.emit(UuidAction(uuid: uuid, action: .scroll(to: previewPosition))) }) .disposed(by: self.disposeBag) } @@ -163,11 +165,11 @@ class PreviewTool: NSView, UiComponent, WKNavigationDelegate { private let webviewMessageHandler = WebviewMessageHandler() private let automaticForwardMenuItem = NSMenuItem(title: "Automatic Forward Search", - action: nil, - keyEquivalent: "") + action: nil, + keyEquivalent: "") private let automaticReverseMenuItem = NSMenuItem(title: "Automatic Reverse Search", - action: nil, - keyEquivalent: "") + action: nil, + keyEquivalent: "") private let refreshOnWriteMenuItem = NSMenuItem(title: "Refresh on Write", action: nil, keyEquivalent: "") private let log = OSLog(subsystem: Defs.loggerSubsystem,