Beispiel #1
0
    def testCurrentModeIsCarriedOver(self):
        self.state.mode = MODE_VISUAL
        cmd_data = CmdData(self.state)
        self.assertEqual(cmd_data['mode'], MODE_VISUAL)

        self.state.mode = MODE_VISUAL_LINE
        cmd_data = CmdData(self.state)
        self.assertEqual(cmd_data['mode'], MODE_VISUAL_LINE)
Beispiel #2
0
    def parse_motion(self):
        """Returns a CmdData instance with parsed motion data.
        """
        vi_cmd_data = CmdData(self)

        # This should happen only at initialization.
        # XXX: This is effectively zeroing xpos. Shouldn't we move this into new_vi_cmd_data()?
        # XXX: REFACTOR
        if vi_cmd_data['xpos'] is None:
            xpos = 0
            if self.view.sel():
                xpos = self.view.rowcol(self.view.sel()[0].b)
            self.xpos = xpos
            vi_cmd_data['xpos'] = xpos

        # Actions originating in normal mode are run in a pseudomode that helps to distiguish
        # between visual mode and this case (both use selections, either implicitly or
        # explicitly).
        if self.action and (self.mode == MODE_NORMAL):
            vi_cmd_data['mode'] = _MODE_INTERNAL_NORMAL

        motion = self.motion
        motion_func = None
        if motion:
            try:
                motion_func = getattr(motions, self.motion)
            except AttributeError:
                raise AttributeError(
                    "Vintageous: Unknown motion: '{0}'".format(self.motion))

        if motion_func:
            vi_cmd_data = motion_func(vi_cmd_data)

        return vi_cmd_data
Beispiel #3
0
 def setUp(self):
     state = mock.Mock()
     state.count = 100
     state.user_provided_count = 200
     state.register = 300
     state.mode = 400
     state.user_input = 500
     state.last_buffer_search = 600
     state.last_character_search = 700
     state.xpos = 800
     self.state = state
     self.cmd_data = CmdData(self.state)
Beispiel #4
0
    def testCanBeInitialized(self):
        cmd_data = CmdData(self.state)
        self.assertEqual(self.cmd_data['count'], 100)
        self.assertEqual(self.cmd_data['_user_provided_count'], 200)
        self.assertEqual(self.cmd_data['register'], 300)
        self.assertEqual(self.cmd_data['mode'], 400)
        self.assertEqual(self.cmd_data['user_input'], 500)
        self.assertEqual(self.cmd_data['last_buffer_search'], 600)
        self.assertEqual(self.cmd_data['last_character_search'], 700)
        self.assertEqual(self.cmd_data['xpos'], 800)

        self.assertEqual(self.cmd_data['pre_motion'], None)
        self.assertEqual(self.cmd_data['motion'], {})
        self.assertEqual(self.cmd_data['motion_required'], True)
        self.assertEqual(self.cmd_data['action'], {})
        self.assertEqual(self.cmd_data['post_action'], None)
        self.assertEqual(self.cmd_data['pre_every_motion'], None)
        self.assertEqual(self.cmd_data['post_every_motion'], None)
        self.assertEqual(self.cmd_data['post_motion'], [])
        self.assertEqual(self.cmd_data['can_yank'], False)
        self.assertEqual(self.cmd_data['yanks_linewise'], False)
        self.assertEqual(self.cmd_data['reposition_caret'], None)
        self.assertEqual(self.cmd_data['follow_up_mode'], None)
        self.assertEqual(self.cmd_data['is_digraph_start'], False)
        self.assertEqual(self.cmd_data['__reorient_caret'], False)
        self.assertEqual(self.cmd_data['is_jump'], False)
        self.assertEqual(self.cmd_data['creates_jump_at_current_position'],
                         False)
        self.assertEqual(self.cmd_data['cancel_action_if_motion_fails'], False)
        self.assertEqual(self.cmd_data['_repeat_action'], False)
        self.assertEqual(self.cmd_data['restore_original_carets'], False)
        self.assertEqual(self.cmd_data['must_update_xpos'], True)
        self.assertEqual(self.cmd_data['scroll_into_view'], True)
        self.assertEqual(self.cmd_data['scroll_command'], None)
        self.assertEqual(self.cmd_data['_change_mode_to'], None)
        self.assertEqual(self.cmd_data['_exit_mode'], None)
        self.assertEqual(self.cmd_data['_exit_mode_command'], None)
        self.assertEqual(self.cmd_data['must_blink_on_error'], False)
        self.assertEqual(self.cmd_data['next_mode'], MODE_NORMAL)
        self.assertEqual(self.cmd_data['selection_modifier'], None)
        self.assertEqual(self.cmd_data['align_with_xpos'], False)
        self.assertEqual(self.cmd_data['last_motion'], None)
        self.assertEqual(self.cmd_data['synthetize_new_line_at_eof'], False)
        self.assertEqual(self.cmd_data['_mark_groups_for_gluing'], True)
        self.assertEqual(self.cmd_data['populates_small_delete_register'],
                         False)
        self.assertEqual(self.cmd_data['is_window_command'], False)
        self.assertEqual(self.cmd_data['has_training_wheels'], False)
        self.assertEqual(self.cmd_data['keep_selection_as_is'], False)
Beispiel #5
0
    def testCaretEndsInExpectedRegion(self):
        set_text(self.view, ''.join(('foo bar\nfoo bar\nfoo bar\n', )))
        add_sel(self.view, self.R((1, 3), (1, 0)))

        state = VintageState(self.view)
        state.enter_visual_mode()

        # TODO: we should bypass vi_r and define the values directly.
        data = CmdData(state)
        data = vi_r(data)
        data['action']['args']['character'] = 'X'

        self.view.run_command('vi_run', data)

        self.assertEqual(self.R((1, 0), (1, 0)), first_sel(self.view))
Beispiel #6
0
 def setUp(self):
     state = mock.Mock()
     state.count = 100
     state.user_provided_count = 200
     state.register = 300
     state.mode = 400
     state.user_input = 500
     state.last_buffer_search = 600
     state.last_character_search = 700
     state.xpos = 800
     self.state = state
     self.state.settings.vi = {
         'user_motion_input': 'foo',
         'user_action_input': 'bar'
     }
     self.cmd_data = CmdData(self.state)
Beispiel #7
0
 def testCanRunActionWhenThereAreNonEmptySelections(self):
     self.state.action = 'vi_d'
     self.state.view.sel().clear()
     self.state.view.sel().add(sublime.Region(10, 20))
     new_cmd_data = self.state.parse_action(CmdData(self.state))
     self.assertFalse(new_cmd_data['motion_required'])
Beispiel #8
0
 def testCmdDataIsntModifiedIfThereIsNoAction(self):
     # FIXME: The following creates a dependency in this test.
     self.state.action = 'vi_d'
     new_cmd_data = self.state.parse_action(CmdData(self.state))
     self.assertEqual(new_cmd_data['action']['command'], 'left_delete')
Beispiel #9
0
 def testCanParseNoneMotion(self):
     cmd_data = CmdData(self.state)
     self.assertRaises(TypeError, self.state.parse_action, cmd_data)
Beispiel #10
0
 def testCantParseWithUnknownMotion(self):
     self.state.action = 'foobar'
     cmd_data = CmdData(self.state)
     self.assertRaises(AttributeError, self.state.parse_action, cmd_data)
Beispiel #11
0
 def testCmdDataDoesntChangeIfNoMotionProvided(self):
     cmd_data = CmdData(self.state)
     cmd_data['xpos'] = (0, 0)
     new_cmd_data = self.state.parse_motion()
     self.assertEqual(cmd_data, new_cmd_data)