+_ = require 'underscore-plus'
{Operator} = require './general-operators'
class AdjustIndentation extends Operator
- execute: (count=1) ->
+ execute: (count) ->
mode = @vimState.mode
@motion.select(count)
- {start} = @editor.getSelectedBufferRange()
+ originalRanges = @editor.getSelectedBufferRanges()
- @indent()
+ if mode is 'visual'
+ @editor.transact =>
+ _.times(count ? 1, => @indent())
+ else
+ @indent()
- if mode isnt 'visual'
- @editor.setCursorBufferPosition([start.row, 0])
- @editor.moveToFirstCharacterOfLine()
- @vimState.activateCommandMode()
+ @editor.clearSelections()
+ @editor.getLastCursor().setBufferPosition([originalRanges.shift().start.row, 0])
+ for range in originalRanges
+ @editor.addCursorAtBufferPosition([range.start.row, 0])
+ @editor.moveToFirstCharacterOfLine()
+ @vimState.activateNormalMode()
class Indent extends AdjustIndentation
indent: ->