       unless @editor.hasMultipleCursors()
         @clearRangeMarkers() if settings.get('clearRangeMarkerOnResetNormalMode')
         @main.clearHighlightSearchForEditors() if settings.get('clearHighlightSearchOnResetNormalMode')
+        @deactivatePresetOccurrenceMode() if @hasPresetOccurrence()
+
     @editor.clearSelections()
     @activate('normal')
 

  getVisibleBufferRange
  matchScopes
  isRangeContainsSomePoint

  debug
} = require './utils'


  # Occurrence request for next operation
  # -------------------------
  hasPresetOccurrence: ->
    @presetOccurrenceDeactivator?

  deactivatePresetOccurrenceMode: (clearMarkers=true) ->
    @presetOccurrenceDeactivator?.dispose()
    @presetOccurrenceDeactivator = null

    @editorElement.classList.remove("occurrence-preset")
    @operationStack.clearOccurrenceMarkers() if clearMarkers

  presetOccurrenceDeactivator: null
  presetOccurrence: (pattern=null) ->
    if not pattern? and @isMode('visual') and text = @editor.getSelectedText()
      pattern = new RegExp(_.escapeRegExp(text), 'g')
      @activate('normal')

    pattern ?= getWordPatternAtCursor(@editor.getLastCursor(), singleNonWordChar: true)

    @editorElement.classList.add("occurrence-preset")

    @presetOccurrenceDeactivator = @emitter.on 'did-push-operation', (operation) =>
      if operation.isOperator() and operation.canAcceptPresetOccurrence()
        @deactivatePresetOccurrenceMode(false)
        @operationStack.clearOccurrenceMarkersOnReset()
        operation.patternForOccurence = pattern
        operation.occurrence = true

    # refresh
    @operationStack.clearOccurrenceMarkers()
