 _ = require 'underscore-plus'
 {CompositeDisposable} = require 'atom'
+{inspect} = require 'util'
 
 requireFrom = (pack, path) ->
   packPath = atom.packages.resolvePackagePath(pack)

        @countTimes =>
          for selection, i in selections
            @selectionIndex = i
            @mutate(selection) if @isMovable(selection)

  initOverwrittenByEditor: ->
    unless overwrittenByEditor.has(@editor)
      if @isLinewise()
        rowCount = swrap(@editor.getLastSelection()).getRowCount()
        overwrittenArea = [1..rowCount].map -> ''
      else
        width = @editor.getLastSelection().getBufferRange().getExtent().column
        overwrittenArea = @editor.getSelections().map (selection) ->
          _.multiplyString(' ', width)
      overwrittenByEditor.set(@editor, overwrittenArea)

  getSelectedTexts: ->

      @editor.groupChangesSinceCheckpoint(checkpoint)

  getOverwrittenText: (replacedText) ->
    overwrittenArea = overwrittenByEditor.get(@editor)[@selectionIndex]
    replacedText = switch @direction
      when 'up'
        [overwritten, rest...] = overwrittenArea.split("\n")
        overwrittenArea = [rest..., replacedText].join("\n")
        overwritten
      when 'down'
        [rest..., overwritten] = overwrittenArea.split("\n")
        overwrittenArea = [replacedText, rest...].join("\n")
        overwritten
      when 'right'
        [overwritten, rest...] = overwrittenArea
        overwrittenArea = [rest..., replacedText].join("")
        overwritten
      when 'left'
        [rest..., overwritten] = overwrittenArea
        overwrittenArea = [replacedText, rest...].join("")
        overwritten

    overwrittenByEditor.get(@editor)[@selectionIndex] = overwrittenArea
    replacedText

  isLinewise: ->
    switch @vimState.submode
