diff --git a/VimR/VimR/Base.lproj/MainMenu.xib b/VimR/VimR/Base.lproj/MainMenu.xib index a0eed151..1c69ad33 100644 --- a/VimR/VimR/Base.lproj/MainMenu.xib +++ b/VimR/VimR/Base.lproj/MainMenu.xib @@ -220,17 +220,17 @@ - + - + - + @@ -279,7 +279,8 @@ - + + diff --git a/VimR/VimR/BufferList.swift b/VimR/VimR/BufferList.swift index 174ad412..206a1c4b 100644 --- a/VimR/VimR/BufferList.swift +++ b/VimR/VimR/BufferList.swift @@ -48,6 +48,11 @@ class BuffersList: NSView, source .observeOn(MainScheduler.instance) .subscribe(onNext: { state in + if state.viewToBeFocused != nil, + case .bufferList = state.viewToBeFocused! { + self.beFirstResponder() + } + let themeChanged = changeTheme( themePrefChanged: state.appearance.usesTheme != self.usesTheme, themeChanged: state.appearance.theme.mark != self.lastThemeMark, diff --git a/VimR/VimR/DefaultShortcuts.swift b/VimR/VimR/DefaultShortcuts.swift index d151a640..0c2645d3 100644 --- a/VimR/VimR/DefaultShortcuts.swift +++ b/VimR/VimR/DefaultShortcuts.swift @@ -111,6 +111,24 @@ let defaultShortcuts: [String: [String: Any]] = [ SRShortcutKeyCode: 18, SRShortcutModifierFlagsKey: 1048840, ], + "com.qvacua.vimr.menuitems.tools.toggle-buffer-list": [ + SRShortcutCharacters: "1", + SRShortcutCharactersIgnoringModifiers: "2", + SRShortcutKeyCode: 19, + SRShortcutModifierFlagsKey: 1048840, + ], + "com.qvacua.vimr.menuitems.tools.toggle-markdown-preview": [ + SRShortcutCharacters: "1", + SRShortcutCharactersIgnoringModifiers: "3", + SRShortcutKeyCode: 20, + SRShortcutModifierFlagsKey: 1048840, + ], + "com.qvacua.vimr.menuitems.tools.toggle-html-preview": [ + SRShortcutCharacters: "1", + SRShortcutCharactersIgnoringModifiers: "4", + SRShortcutKeyCode: 21, + SRShortcutModifierFlagsKey: 1048840, + ], "com.qvacua.vimr.menuitems.tools.toggle-tool-buttons": [ SRShortcutCharacters: "\\", SRShortcutCharactersIgnoringModifiers: "|", diff --git a/VimR/VimR/HtmlPreviewTool.swift b/VimR/VimR/HtmlPreviewTool.swift index dab02215..ef1319ed 100644 --- a/VimR/VimR/HtmlPreviewTool.swift +++ b/VimR/VimR/HtmlPreviewTool.swift @@ -45,6 +45,11 @@ class HtmlPreviewTool: NSView, UiComponent, WKNavigationDelegate { source .observeOn(MainScheduler.instance) .subscribe(onNext: { [unowned self] state in + if state.viewToBeFocused != nil, + case .htmlPreview = state.viewToBeFocused! { + self.beFirstResponder() + } + guard let serverUrl = state.htmlPreview.server, let htmlFileUrl = state.htmlPreview.htmlFile else { self.monitor = nil return diff --git a/VimR/VimR/MainWindow+Actions.swift b/VimR/VimR/MainWindow+Actions.swift index 06a119f1..81c68d19 100644 --- a/VimR/VimR/MainWindow+Actions.swift +++ b/VimR/VimR/MainWindow+Actions.swift @@ -123,38 +123,43 @@ extension MainWindow { } @IBAction func toggleFileBrowser(_ sender: Any?) { - let fileBrowser = self.fileBrowserContainer + guard let fileBrowser = self.fileBrowserContainer else { return } + self.toggle(tool: fileBrowser, toolType: .fileBrowser) + } - if fileBrowser?.isSelected == true { - if fileBrowser?.view.isFirstResponder == true { - fileBrowser?.toggle() + @IBAction func toggleBufferList(_ sender: Any?) { + guard let bufferList = self.buffersListContainer else { return } + self.toggle(tool: bufferList, toolType: .bufferList) + } + + @IBAction func toggleMarkdownPreview(_ sender: Any?) { + guard let markdownPreview = self.previewContainer else { return } + self.toggle(tool: markdownPreview, toolType: .markdownPreview) + } + + @IBAction func toggleHtmlPreview(_ sender: Any?) { + guard let htmlPreview = self.htmlPreviewContainer else { return } + self.toggle(tool: htmlPreview, toolType: .htmlPreview) + } + + @IBAction func focusNvimView(_: Any?) { + self.emit(self.uuidAction(for: .focus(.neoVimView))) + } + + private func toggle(tool: WorkspaceTool, toolType: FocusableView) { + if tool.isSelected == true { + if tool.view.isFirstResponder == true { + tool.toggle() self.focusNvimView(self) } else { - self.emit(self.uuidAction(for: .focus(.fileBrowser))) + self.emit(self.uuidAction(for: .focus(toolType))) } return } - fileBrowser?.toggle() - self.emit(self.uuidAction(for: .focus(.fileBrowser))) - } - - @IBAction func toggleBufferList(_ sender: Any?) { - - } - - @IBAction func toggleMarkdownPreview(_ sender: Any?) { - - } - - @IBAction func toggleHtmlPreview(_ sender: Any?) { - - } - - @IBAction func focusNvimView(_: Any?) { -// self.window.makeFirstResponder(self.neoVimView) - self.emit(self.uuidAction(for: .focus(.neoVimView))) + tool.toggle() + self.emit(self.uuidAction(for: .focus(toolType))) } } diff --git a/VimR/VimR/PreviewTool.swift b/VimR/VimR/PreviewTool.swift index f02be862..490fcd17 100644 --- a/VimR/VimR/PreviewTool.swift +++ b/VimR/VimR/PreviewTool.swift @@ -80,7 +80,8 @@ class PreviewTool: NSView, UiComponent, WKNavigationDelegate { source .observeOn(MainScheduler.instance) .subscribe(onNext: { state in - if state.viewToBeFocused != nil, case .markdownPreview = state.viewToBeFocused! { + if state.viewToBeFocused != nil, + case .markdownPreview = state.viewToBeFocused! { self.beFirstResponder() }