 
   # Markers
   # -------------------------
+  clearMarkers: (pattern) ->
+    for marker in @markerLayer.getMarkers()
+      marker.destroy()
+
   hasMarkers: ->
     @markerLayer.getMarkerCount() > 0
 

module.exports =
class OccurrenceManager
  patterns: null

  constructor: (@vimState) ->
    {@editor, @editorElement} = @vimState

    @patterns = []

    @markerLayer = @editor.addMarkerLayer()
    @decorationLayer = @editor.decorateMarkerLayer(@markerLayer, @decorationOptions)

    # @patterns is single source of truth (SSOT)
    # All maker create/destroy/css-update is done by reacting @patters's change.
    # -------------------------
    @onDidChangePatterns ({newPattern}) =>
      if newPattern
        @markBufferRangeByPattern(newPattern)
      else
        @clearMarkers()

    # Update css on every marker update.
    @markerLayer.onDidUpdate =>
      @editorElement.classList.toggle("has-occurrence", @hasMarkers())

  markBufferRangeByPattern: (pattern) ->
    for range in scanEditor(@editor, pattern)
      @markerLayer.markBufferRange(range, @markerOptions)

  # Callback get passed following object
  # - newPattern: can be undefined on reset event
