1 min read

Atom in windows regain focus with significant delay

Among the code editors Atom is my favorite. Before using Atom, I used Sublime heavily. I also tried Visual Studio Code. But Atom is my ultimate choice. There are lots of reasons behind that. One of the choices, I should mention, git enabled multi project folder.

A few days ago, suddenly a strange behavior observed by me and that was pretty annoying. It took approximately 1.5 sec to get focus the editor when switching between windows. Web developers frequently need to change windows even monitors to effectively coding and previewing the results.

At first I could not understand why this was occurring. Then googled it and found that the GitRefreshOnFocus function of the Atom editor block that time. According to the instruction of atom support, I had to modify the init script of the editor by adding the following function in it.

disableGitRefreshOnFocus = ->
  atom.project.repositories.forEach (repo) ->
    if repo and repo.subscriptions and repo.subscriptions.disposables and repo.subscriptions.disposables.size
        Array.from(repo.subscriptions.disposables).forEach (item) ->
          content = item.disposalAction + ''
          if content.indexOf('focus') > 1
            item.dispose()
          return
  return

atom.project.emitter.on "did-change-paths", disableGitRefreshOnFocus
disableGitRefreshOnFocus()

This code will disable git refresh on focus by default. But if you want to manually refresh git status, add the following code into the same init.coffee script.

atom.commands.add 'atom-text-editor', 'custom:refresh-git-status', ->
    atom.project.repositories.forEach (repo) ->
      repo.refreshStatus()

Then open the keymap.cson file and paste the following code.

'atom-text-editor':
    'ctrl-shift-g': 'custom:refresh-git-status'

So, ctrl+shift+g shortcut will refresh the git repository status.

Thanks Atom and this support issue.