Skip to content

Commit

Permalink
Fix cursor at end of line
Browse files Browse the repository at this point in the history
  • Loading branch information
bgallois committed Jun 9, 2020
1 parent 89114fb commit 5aa9ec6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spyder_vim/tests/test_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@ def test_backward_search_regex_command(vim_bot):
assert index_test == [4, 3, 2, 1, 4, 1, 2, 3, 4, 1]


def test_cursor_position(vim_bot):
"""Test cursor position"""
main, editor_stack, editor, vim, qtbot = vim_bot
editor.stdkey_backspace()
editor.go_to_line(3)
editor.moveCursor(QTextCursor.StartOfLine, QTextCursor.KeepAnchor)
cmd_line = vim.get_focus_widget()
qtbot.keyClicks(cmd_line, '$a')
qtbot.keyClicks(editor, 'test')
editor.stdkey_escape()
text = editor.toPlainText()
expected_text = (' 123\n'
'line 1\n'
'line 2test\n'
'line 3\n'
'line 4')
assert text == expected_text
_, col = editor.get_cursor_line_column()
assert col == 10


def test_select_command_brackets(vim_bot):
"""Test a selection"""
main, editor_stack, editor, vim, qtbot = vim_bot
Expand Down
13 changes: 13 additions & 0 deletions spyder_vim/vim_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ def exit_visual_mode(self):
self._widget.update_vim_cursor()
self.visual_mode = False

def exit_insert_mode(self):
"""Exit insert mode."""
self.mode_changed.emit("normal")
editor = self._widget.editor()
cursor = self._editor_cursor()
editor.clear_extra_selections('vim_visual')
if cursor.atBlockEnd():
self.h()
self._widget.update_vim_cursor()

def search(self, key, reverse=False):
""""Search regular expressions key inside document"""
editor = self._widget.editor()
Expand Down Expand Up @@ -685,6 +695,7 @@ def o(self, repeat):
cursor.insertText("\n")
editor.setTextCursor(cursor)
editor.setFocus()
self._widget.update_vim_cursor()

def O(self, repeat):
"""Begin a new line above the cursor and insert text."""
Expand All @@ -695,6 +706,7 @@ def O(self, repeat):
cursor.movePosition(QTextCursor.Up)
editor.setTextCursor(cursor)
editor.setFocus()
self._widget.update_vim_cursor()

# %% Editing and cases(visual)
def u(self, repeat):
Expand Down Expand Up @@ -1053,6 +1065,7 @@ def focusInEvent(self, event):
QLineEdit.focusInEvent(self, event)
self.clear()
self.parent().on_mode_changed("normal")
self.parent().vim_keys.exit_insert_mode()

def focusOutEvent(self, event):
"""Enter editor mode."""
Expand Down

0 comments on commit 5aa9ec6

Please sign in to comment.