1 {MotionWithInput} = require './general-motions'
2 {ViewModel} = require '../view-models/view-model'
3 {Point, Range} = require 'atom'
5 class Find extends MotionWithInput
6 operatesInclusively: true
8 constructor: (@editor, @vimState, opts={}) ->
9 super(@editor, @vimState)
13 @viewModel = new ViewModel(this, class: 'find', singleChar: true, hidden: true)
16 @vimState.globalVimState.currentFind = this
21 orig = @vimState.globalVimState.currentFind
22 @backwards = orig.backwards
23 @complete = orig.complete
26 @reverse() if opts.reverse
28 match: (cursor, count) ->
29 currentPosition = cursor.getBufferPosition()
30 line = @editor.lineTextForBufferRow(currentPosition.row)
32 index = currentPosition.column
34 return if index <= 0 # we can't move backwards any further, quick return
35 index = line.lastIndexOf(@input.characters, index-1-(@offset*@repeated))
37 new Point(currentPosition.row, index + @offset)
39 index = currentPosition.column
41 index = line.indexOf(@input.characters, index+1+(@offset*@repeated))
42 return if index < 0 # no match found
44 new Point(currentPosition.row, index - @offset)
47 @backwards = not @backwards
50 moveCursor: (cursor, count=1) ->
51 if (match = @match(cursor, count))?
52 cursor.setBufferPosition(match)
54 class Till extends Find
55 constructor: (@editor, @vimState, opts={}) ->
56 super(@editor, @vimState, opts)
60 @selectAtLeastOne = false
62 if retval? and not @backwards
63 @selectAtLeastOne = true
66 moveSelectionInclusively: (selection, count, options) ->
68 if selection.isEmpty() and @selectAtLeastOne
69 selection.modifySelection ->
70 selection.cursor.moveRight()
72 module.exports = {Find, Till}