diff --git a/VimR/Context.swift b/VimR/Context.swift index b3e7c537..aeca0d04 100644 --- a/VimR/Context.swift +++ b/VimR/Context.swift @@ -91,7 +91,7 @@ class Context { .disposed(by: self.disposeBag) #if DEBUG -// actionSource.debug().subscribe().disposed(by: self.disposeBag) +// self.actionEmitter.observable.debug().subscribe().disposed(by: self.disposeBag) // stateSource.debug().subscribe().disposed(by: self.disposeBag) #endif } @@ -122,6 +122,8 @@ class Context { fileprivate func cleanUpAppState() { self.appState.mainWindows.keys.forEach { uuid in + self.appState.mainWindows[uuid]?.cwdToSet = nil + self.appState.mainWindows[uuid]?.currentBufferToSet = nil self.appState.mainWindows[uuid]?.viewToBeFocused = nil self.appState.mainWindows[uuid]?.urlsToOpen.removeAll() } diff --git a/VimR/FileBrowserReducer.swift b/VimR/FileBrowserReducer.swift index 3332a7bb..d02112f5 100644 --- a/VimR/FileBrowserReducer.swift +++ b/VimR/FileBrowserReducer.swift @@ -19,7 +19,7 @@ class FileBrowserReducer { state.viewToBeFocused = .neoVimView case let .setAsWorkingDirectory(url): - state.cwd = url + state.cwdToSet = url case let .setShowHidden(show): state.fileBrowserShowHidden = show diff --git a/VimR/MainWindow.swift b/VimR/MainWindow.swift index b46c9c66..9b8c0fed 100644 --- a/VimR/MainWindow.swift +++ b/VimR/MainWindow.swift @@ -187,9 +187,9 @@ class MainWindow: NSObject, self.windowController.setDocumentEdited(state.isDirty) -// if self.neoVimView.cwd != state.cwd { -// self.neoVimView.cwd = state.cwd -// } + if let cwd = state.cwdToSet { + self.neoVimView.cwd = cwd + } if state.previewTool.isReverseSearchAutomatically && state.preview.previewPosition.hasDifferentMark(as: self.previewPosition) @@ -203,11 +203,8 @@ class MainWindow: NSObject, self.open(urls: state.urlsToOpen) - if self.currentBuffer != state.currentBuffer { - self.currentBuffer = state.currentBuffer - if let currentBuffer = self.currentBuffer { - self.neoVimView.select(buffer: currentBuffer) - } + if let currentBuffer = state.currentBufferToSet { + self.neoVimView.select(buffer: currentBuffer) } if self.defaultFont != state.appearance.font @@ -248,7 +245,9 @@ class MainWindow: NSObject, fileprivate var currentBuffer: NeoVimBuffer? fileprivate let windowController: NSWindowController - fileprivate var window: NSWindow { return self.windowController.window! } + fileprivate var window: NSWindow { + return self.windowController.window! + } fileprivate var defaultFont: NSFont fileprivate var linespacing: CGFloat @@ -444,9 +443,10 @@ extension MainWindow { let urls = panel.urls if self.neoVimView.allBuffers().count == 1 { let isTransient = self.neoVimView.allBuffers().first?.isTransient ?? false -// if isTransient { -// self.neoVimView.cwd = FileUtils.commonParent(of: urls) -// } + + if isTransient { + self.neoVimView.cwd = FileUtils.commonParent(of: urls) + } } self.neoVimView.open(urls: urls) } diff --git a/VimR/OpenedFileListReducer.swift b/VimR/OpenedFileListReducer.swift index e5834df0..7f54c5eb 100644 --- a/VimR/OpenedFileListReducer.swift +++ b/VimR/OpenedFileListReducer.swift @@ -15,7 +15,7 @@ class OpenedFileListReducer { switch pair.action { case let .open(buffer): - state.currentBuffer = buffer + state.currentBufferToSet = buffer } diff --git a/VimR/States.swift b/VimR/States.swift index b1e5e67a..31c9dfd7 100644 --- a/VimR/States.swift +++ b/VimR/States.swift @@ -223,6 +223,8 @@ extension MainWindow { // to be cleaned var urlsToOpen = [URL: OpenMode]() + var currentBufferToSet: NeoVimBuffer? + var cwdToSet: URL? var viewToBeFocused: FocusableView? = FocusableView.neoVimView init(isAllToolsVisible: Bool, isToolButtonsVisible: Bool) {