From b2be663e6ae7445b5634d8d8fadcf1935375d25a Mon Sep 17 00:00:00 2001 From: Pietro De Nicolao Date: Sun, 21 May 2017 00:06:30 +0200 Subject: [PATCH] Fix focus (ctrl+alt+F) shortcut behaviour (#218) * Fix focus issue when terminal is not active https://github.com/platformio/platformio-atom-ide-terminal/issues/189 * blurring terminal return focus to previous element * lastActive element is now updated at each terminal focus --- lib/status-bar.coffee | 10 +++++++++- lib/view.coffee | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/status-bar.coffee b/lib/status-bar.coffee index 9caddef..b0f6eb3 100644 --- a/lib/status-bar.coffee +++ b/lib/status-bar.coffee @@ -23,7 +23,7 @@ class StatusBar extends View @subscriptions = new CompositeDisposable() @subscriptions.add atom.commands.add 'atom-workspace', - 'platformio-ide-terminal:focus': => @activeTerminal.focusTerminal() + 'platformio-ide-terminal:focus': => @focusTerminal() 'platformio-ide-terminal:new': => @newTerminalView() 'platformio-ide-terminal:toggle': => @toggle() 'platformio-ide-terminal:next': => @@ -212,6 +212,14 @@ class StatusBar extends View getActiveTerminalView: -> return @activeTerminal + focusTerminal: -> + return unless @activeTerminal? + + if terminal = PlatformIOTerminalView.getFocusedTerminal() + @activeTerminal.blur() + else + @activeTerminal.focusTerminal() + getTerminalById: (target, selector) -> selector ?= (terminal) -> terminal.id diff --git a/lib/view.coffee b/lib/view.coffee index 43ece89..7f1cb03 100644 --- a/lib/view.coffee +++ b/lib/view.coffee @@ -467,6 +467,8 @@ class PlatformIOTerminalView extends View focusTerminal: => return unless @terminal + lastActiveElement = $(document.activeElement) + @terminal.focus() if @terminal._textarea @terminal._textarea.focus() @@ -479,6 +481,9 @@ class PlatformIOTerminalView extends View @terminal.blur() @terminal.element.blur() + if lastActiveElement? + lastActiveElement.focus() + resizeTerminalToView: -> return unless @panel.isVisible() or @tabView