]> git.r.bdr.sh - rbdr/dotfiles/blobdiff - atom/packages/vim-mode/lib/motions/find-motion.coffee
Adds editorconfig
[rbdr/dotfiles] / atom / packages / vim-mode / lib / motions / find-motion.coffee
index 58685d7087646782b43c2e1186cac38a6a26030c..2a577a8b03ff74672ffa3b93260ad733d36fff8d 100644 (file)
@@ -3,14 +3,27 @@
 {Point, Range} = require 'atom'
 
 class Find extends MotionWithInput
-  constructor: (@editor, @vimState) ->
+  operatesInclusively: true
+
+  constructor: (@editor, @vimState, opts={}) ->
     super(@editor, @vimState)
-    @vimState.currentFind = this
-    @viewModel = new ViewModel(this, class: 'find', singleChar: true, hidden: true)
-    @backwards = false
-    @repeatReversed = false
     @offset = 0
-    @repeated = false
+
+    if not opts.repeated
+      @viewModel = new ViewModel(this, class: 'find', singleChar: true, hidden: true)
+      @backwards = false
+      @repeated = false
+      @vimState.globalVimState.currentFind = this
+
+    else
+      @repeated = true
+
+      orig = @vimState.globalVimState.currentFind
+      @backwards = orig.backwards
+      @complete = orig.complete
+      @input = orig.input
+
+      @reverse() if opts.reverse
 
   match: (cursor, count) ->
     currentPosition = cursor.getBufferPosition()
@@ -38,17 +51,22 @@ class Find extends MotionWithInput
     if (match = @match(cursor, count))?
       cursor.setBufferPosition(match)
 
-  repeat: (opts={}) ->
-    opts.reverse = !!opts.reverse
-    @repeated = true
-    if opts.reverse isnt @repeatReversed
-      @reverse()
-      @repeatReversed = opts.reverse
-    this
-
 class Till extends Find
-  constructor: (@editor, @vimState) ->
-    super(@editor, @vimState)
+  constructor: (@editor, @vimState, opts={}) ->
+    super(@editor, @vimState, opts)
     @offset = 1
 
+  match: ->
+    @selectAtLeastOne = false
+    retval = super
+    if retval? and not @backwards
+      @selectAtLeastOne = true
+    retval
+
+  moveSelectionInclusively: (selection, count, options) ->
+    super
+    if selection.isEmpty() and @selectAtLeastOne
+      selection.modifySelection ->
+        selection.cursor.moveRight()
+
 module.exports = {Find, Till}