 
   refresh: ->
     @clearMarkers()
-    if matchScopes(@editorElement, settings.get('highlightSearchExcludeScopes'))
-      return
 
-    unless settings.get('highlightSearch')
-      return
+    return unless settings.get('highlightSearch')
+    return unless @vimState.isVisible()
+    return unless pattern = @globalState.get('highlightSearchPattern')
+    return if matchScopes(@editorElement, settings.get('highlightSearchExcludeScopes'))
 
-    if pattern = @globalState.get('highlightSearchPattern')
-      for range in scanEditor(@editor, pattern)
-        @markerLayer.markBufferRange(range)
+    for range in scanEditor(@editor, pattern)
+      @markerLayer.markBufferRange(range)

    # Refresh highlight based on globalState.highlightSearchPattern changes.
    # -------------------------
    @disposables = @globalState.onDidChange ({name, newValue}) =>
      @refresh() if name is 'highlightSearchPattern'

  destroy: ->
    @decorationLayer.destroy()

  constructor: (@vimState) ->
    {@editor, @editorElement, @globalState} = @vimState
    @disposables = new CompositeDisposable
    @markerLayer = @editor.addMarkerLayer()

    options =
      type: 'highlight'
      invalidate: 'inside'
