1 {MotionWithInput} = require './general-motions'
2 {ViewModel} = require '../view-models/view-model'
3 {Point, Range} = require 'atom'
5 class Find extends MotionWithInput
6 constructor: (@editor, @vimState) ->
7 super(@editor, @vimState)
8 @vimState.currentFind = this
9 @viewModel = new ViewModel(this, class: 'find', singleChar: true, hidden: true)
11 @repeatReversed = false
15 match: (cursor, count) ->
16 currentPosition = cursor.getBufferPosition()
17 line = @editor.lineTextForBufferRow(currentPosition.row)
19 index = currentPosition.column
21 return if index <= 0 # we can't move backwards any further, quick return
22 index = line.lastIndexOf(@input.characters, index-1-(@offset*@repeated))
24 new Point(currentPosition.row, index + @offset)
26 index = currentPosition.column
28 index = line.indexOf(@input.characters, index+1+(@offset*@repeated))
29 return if index < 0 # no match found
31 new Point(currentPosition.row, index - @offset)
34 @backwards = not @backwards
37 moveCursor: (cursor, count=1) ->
38 if (match = @match(cursor, count))?
39 cursor.setBufferPosition(match)
42 opts.reverse = !!opts.reverse
44 if opts.reverse isnt @repeatReversed
46 @repeatReversed = opts.reverse
49 class Till extends Find
50 constructor: (@editor, @vimState) ->
51 super(@editor, @vimState)
54 module.exports = {Find, Till}