     textForMarker = (marker) ->
       editor.getTextInBufferRange(marker.getBufferRange())
 
-    ensurePersistentSelection = (options) ->
+    ensurePersistentSelection = (args...) ->
+      switch args.length
+        when 1 then [options] = args
+        when 2 then [_keystroke, options] = args
+
+      if _keystroke?
+        keystroke(_keystroke)
+
       markers = vimState.persistentSelection.getMarkers()
       if options.length?
         expect(markers).toHaveLength(options.length)


    describe "clearPersistentSelections command", ->
      it "clear persistentSelections", ->
        keystroke('g m i w')
        ensurePersistentSelection length: 1, text: ['ooo']
        dispatch(editorElement, 'vim-mode-plus:clear-persistent-selection')
        expect(vimState.persistentSelection.hasMarkers()).toBe(false)

    describe "clearPersistentSelectionOnResetNormalMode", ->
      describe "default setting", ->
        it "it won't clear persistentSelection", ->
          keystroke('g m i w')
          ensurePersistentSelection length: 1, text: ['ooo']
          dispatch(editorElement, 'vim-mode-plus:reset-normal-mode')
          ensurePersistentSelection length: 1, text: ['ooo']

      describe "when enabled", ->
        it "it clear persistentSelection on reset-normal-mode", ->
          settings.set('clearPersistentSelectionOnResetNormalMode', true)
          keystroke('g m i w')
          ensurePersistentSelection length: 1, text: ['ooo']
          dispatch(editorElement, 'vim-mode-plus:reset-normal-mode')
          expect(vimState.persistentSelection.hasMarkers()).toBe(false)


      it "select all instance of cursor word only within marked range", ->
        runs ->
          paragraphText = "ooo xxx ooo\nxxx ooo xxx\n"
          ensurePersistentSelection 'g m i p } } j .', # Mark 2 inner-word and 1 inner-paragraph
            length: 2
            text: [paragraphText, paragraphText]

        waitsFor ->
          update.callCount is 1
        runs ->
