1 _ = require 'underscore-plus'
2 {OperatorWithInput} = require './general-operators'
3 {ViewModel} = require '../view-models/view-model'
4 {Range} = require 'atom'
7 class Replace extends OperatorWithInput
8 constructor: (@editor, @vimState) ->
9 super(@editor, @vimState)
10 @viewModel = new ViewModel(this, class: 'replace', hidden: true, singleChar: true, defaultText: '\n')
13 if @input.characters is ""
16 if @vimState.mode is "visual"
17 @vimState.resetVisualMode()
19 @vimState.activateNormalMode()
25 if _.contains(@motion.select(), true)
26 @editor.replaceSelectedText null, (text) =>
27 text.replace(/./g, @input.characters)
28 for selection in @editor.getSelections()
29 point = selection.getBufferRange().start
30 selection.setBufferRange(Range.fromPointWithDelta(point, 0, 0))
32 for cursor in @editor.getCursors()
33 pos = cursor.getBufferPosition()
34 currentRowLength = @editor.lineTextForBufferRow(pos.row).length
35 continue unless currentRowLength - pos.column >= count
38 point = cursor.getBufferPosition()
39 @editor.setTextInBufferRange(Range.fromPointWithDelta(point, 0, 1), @input.characters)
41 cursor.setBufferPosition(pos)
43 # Special case: when replaced with a newline move to the start of the
45 if @input.characters is "\n"
48 @editor.moveToFirstCharacterOfLine()
50 @vimState.activateNormalMode()