       marker.destroy()
     , settings.get('flashOnOperateDurationMilliSeconds')
 
-  withFlashing: (callback) ->
-    unless settings.get('flashOnOperate')
-      callback()
-      return
-
-    markerBySelections = @markSelections()
-    callback()
-    for selection in @editor.getSelections()
-      @editor.decorateMarker markerBySelections[selection.id],
-        type: 'highlight'
-        class: 'vim-mode-flash'
-
-    # Ensure destroy all marker
-    setTimeout  ->
-      marker.destroy() for __, marker of markerBySelections
-    , settings.get('flashOnOperateDurationMilliSeconds')
-
-  selectTarget: (callback) ->
-    if @target.select()
-      callback()
-
-  selectTargetWithFlashing: (callback) ->
-    @selectTarget =>
-      @withFlashing ->
-        callback()
+  eachSelection: (fn) ->
+    return unless @target.select()
+    @editor.transact =>
+      for s in @editor.getSelections()
+        if @flashTarget and settings.get('flashOnOperate')
+          @flash s.getBufferRange(), -> fn(s)
+        else
+          fn(s)
 
 class Select extends Operator
   @extend()


    @target.setOptions? excludeWhitespace: true

    @selectTarget =>
      @setTextToRegister @editor.getSelectedText()
      if @target.isLinewise?() and not @typedText?
        for selection in @editor.getSelections()

  @extend()
  hoverText: ':pencil:'
  hoverIcon: ':replace-with-register:'
  flashTarget: true
  execute: ->
    @eachSelection (s) =>
      range = s.getBufferRange()
      newText = @vimState.register.get().text ? s.getText()
      s.deleteSelectedText()
      s.insertText(newText)
      s.cursor.setBufferPosition(range.start)
    @vimState.activateNormalMode()

class ToggleLineComments extends Operator
  @extend()
  hoverText: ':mute:'
  hoverIcon: ':toggle-line-comment:'
  # flashTarget: true
  execute: ->
    markerByCursor = @markCursorBufferPositions()
    @eachSelection (s) ->
      s.toggleLineComments()
    @restoreMarkedCursorPositions markerByCursor
    @vimState.activateNormalMode()

