diff --git a/VimR/VimR/OpenQuicklyReducer.swift b/VimR/VimR/OpenQuicklyReducer.swift index 33872006..95a9a209 100644 --- a/VimR/VimR/OpenQuicklyReducer.swift +++ b/VimR/VimR/OpenQuicklyReducer.swift @@ -17,7 +17,6 @@ class OpenQuicklyReducer: ReducerType { var appState = pair.state appState.openQuickly.open = false - appState.openQuickly.cwd = FileUtils.userHomeUrl switch pair.action { @@ -47,16 +46,10 @@ class OpenQuicklyReducer: ReducerType { case .openQuickly: var appState = pair.state - guard let uuid = appState.currentMainWindowUuid else { - return pair - } - - guard let cwd = appState.mainWindows[uuid]?.cwd else { - return pair - } + guard let uuid = appState.currentMainWindowUuid, + appState.mainWindows[uuid]?.cwd != nil else { return pair } appState.openQuickly.open = true - appState.openQuickly.cwd = cwd return (appState, pair.action, true) diff --git a/VimR/VimR/OpenQuicklyWindow.swift b/VimR/VimR/OpenQuicklyWindow.swift index cd91216e..f4c8722d 100644 --- a/VimR/VimR/OpenQuicklyWindow.swift +++ b/VimR/VimR/OpenQuicklyWindow.swift @@ -47,8 +47,8 @@ class OpenQuicklyWindow: NSObject, private let emit: (Action) -> Void private let disposeBag = DisposeBag() - private(set) var cwd = FileUtils.userHomeUrl private var cwdPathCompsCount = 0 + private var usesVcsIgnores = true private var scanToken = Token() private var fileServicesPerRootUrl: [URL: FileService] = [:] @@ -78,6 +78,13 @@ class OpenQuicklyWindow: NSObject, private func subscription(_ state: StateType) { self.updateRootUrls(state: state) + guard let curWinUuid = state.currentMainWindowUuid, + let curWinState = state.mainWindows[curWinUuid] else { + self.windowController.close() + return + } + + Swift.print(curWinState.usesVcsIgnores) guard state.openQuickly.open else { self.windowController.close() @@ -89,23 +96,25 @@ class OpenQuicklyWindow: NSObject, return } - self.cwd = state.openQuickly.cwd - self.cwdPathCompsCount = self.cwd.pathComponents.count - self.cwdControl.url = self.cwd + let cwd = curWinState.cwd + self.cwdPathCompsCount = cwd.pathComponents.count + self.cwdControl.url = cwd self.searchField.rx .text.orEmpty .throttle(.milliseconds(1 * 500), latest: true, scheduler: MainScheduler.instance) .distinctUntilChanged() .observeOn(MainScheduler.instance) - .subscribe(onNext: { [weak self] pattern in self?.scanAndScore(pattern) }) + .subscribe(onNext: { [weak self] pattern in + guard let fileService = self?.fileServicesPerRootUrl[cwd] else { return } + self?.scanAndScore(pattern, with: fileService) + }) .disposed(by: self.disposeBag) self.windowController.showWindow(self) } - private func scanAndScore(_ pattern: String) { - guard let fileService = self.fileServicesPerRootUrl[self.cwd] else { return } + private func scanAndScore(_ pattern: String, with fileService: FileService) { fileService.stopScanScore() guard pattern.count >= 2 else { @@ -135,7 +144,7 @@ class OpenQuicklyWindow: NSObject, private func updateRootUrls(state: AppState) { let urlsToMonitor = Set(state.mainWindows.map { $1.cwd }) - let currentUrls = Set(self.fileServicesPerRootUrl.map { url, _ in url }) + let currentUrls = Set(self.fileServicesPerRootUrl.map { url, _ in url }) let newUrls = urlsToMonitor.subtracting(currentUrls) let obsoleteUrls = currentUrls.subtracting(urlsToMonitor) diff --git a/VimR/VimR/States.swift b/VimR/VimR/States.swift index e515a539..e5dc7bcc 100644 --- a/VimR/VimR/States.swift +++ b/VimR/VimR/States.swift @@ -80,7 +80,6 @@ extension OpenQuicklyWindow { case ignorePatterns = "ignore-patterns" } - var cwd = FileUtils.userHomeUrl var ignorePatterns = State.defaultIgnorePatterns var ignoreToken = Token() @@ -282,6 +281,8 @@ extension MainWindow { var cliPipePath: String? var envDict: [String: String]? + var usesVcsIgnores = true + var isLeftOptionMeta = false var isRightOptionMeta = false