]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/lib/motions/find-motion.coffee
Remove easymotion plugin
[rbdr/dotfiles] / atom / packages / vim-mode / lib / motions / find-motion.coffee
1 {MotionWithInput} = require './general-motions'
2 {ViewModel} = require '../view-models/view-model'
3 {Point, Range} = require 'atom'
4
5 class Find extends MotionWithInput
6 operatesInclusively: true
7
8 constructor: (@editor, @vimState, opts={}) ->
9 super(@editor, @vimState)
10 @offset = 0
11
12 if not opts.repeated
13 @viewModel = new ViewModel(this, class: 'find', singleChar: true, hidden: true)
14 @backwards = false
15 @repeated = false
16 @vimState.globalVimState.currentFind = this
17
18 else
19 @repeated = true
20
21 orig = @vimState.globalVimState.currentFind
22 @backwards = orig.backwards
23 @complete = orig.complete
24 @input = orig.input
25
26 @reverse() if opts.reverse
27
28 match: (cursor, count) ->
29 currentPosition = cursor.getBufferPosition()
30 line = @editor.lineTextForBufferRow(currentPosition.row)
31 if @backwards
32 index = currentPosition.column
33 for i in [0..count-1]
34 return if index <= 0 # we can't move backwards any further, quick return
35 index = line.lastIndexOf(@input.characters, index-1-(@offset*@repeated))
36 if index >= 0
37 new Point(currentPosition.row, index + @offset)
38 else
39 index = currentPosition.column
40 for i in [0..count-1]
41 index = line.indexOf(@input.characters, index+1+(@offset*@repeated))
42 return if index < 0 # no match found
43 if index >= 0
44 new Point(currentPosition.row, index - @offset)
45
46 reverse: ->
47 @backwards = not @backwards
48 this
49
50 moveCursor: (cursor, count=1) ->
51 if (match = @match(cursor, count))?
52 cursor.setBufferPosition(match)
53
54 class Till extends Find
55 constructor: (@editor, @vimState, opts={}) ->
56 super(@editor, @vimState, opts)
57 @offset = 1
58
59 match: ->
60 @selectAtLeastOne = false
61 retval = super
62 if retval? and not @backwards
63 @selectAtLeastOne = true
64 retval
65
66 moveSelectionInclusively: (selection, count, options) ->
67 super
68 if selection.isEmpty() and @selectAtLeastOne
69 selection.modifySelection ->
70 selection.cursor.moveRight()
71
72 module.exports = {Find, Till}