Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Fix focus (ctrl+alt+F) shortcut behaviour (#218)
Browse files Browse the repository at this point in the history
* Fix focus issue when terminal is not active

#189

* blurring terminal return focus to previous element

* lastActive element is now updated at each terminal focus
  • Loading branch information
pietrodn authored and ivankravets committed May 20, 2017
1 parent c13e745 commit b2be663
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/status-bar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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': =>
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lib/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ class PlatformIOTerminalView extends View
focusTerminal: =>
return unless @terminal

lastActiveElement = $(document.activeElement)

@terminal.focus()
if @terminal._textarea
@terminal._textarea.focus()
Expand All @@ -479,6 +481,9 @@ class PlatformIOTerminalView extends View
@terminal.blur()
@terminal.element.blur()

if lastActiveElement?
lastActiveElement.focus()

resizeTerminalToView: ->
return unless @panel.isVisible() or @tabView

Expand Down

0 comments on commit b2be663

Please sign in to comment.