diff --git a/plugin/PySnipEmu.vim b/plugin/PySnipEmu.vim index 8601f6d..0d74045 100644 --- a/plugin/PySnipEmu.vim +++ b/plugin/PySnipEmu.vim @@ -62,7 +62,7 @@ inoremap =PyVimSnips_JumpBackwards() snoremap :call PyVimSnips_JumpBackwards() " Do not remap this. -snoremap :py PySnipSnippets.backspace() +snoremap :py PySnipSnippets.backspace_while_selected() au CursorMovedI * py PySnipSnippets.cursor_moved() au InsertEnter * py PySnipSnippets.entered_insert_mode() diff --git a/plugin/PySnipEmu/__init__.py b/plugin/PySnipEmu/__init__.py index 62b6699..babbe38 100644 --- a/plugin/PySnipEmu/__init__.py +++ b/plugin/PySnipEmu/__init__.py @@ -304,18 +304,7 @@ class SnippetManager(object): if self._vstate.moved.col <= 0 and self._vstate.moved.line == 1: self._chars_entered('\n') elif self._vstate.moved.col < 0: # Some deleting was going on - sline = self._csnippet.abs_start.line - dlines = self._csnippet.end.line - self._csnippet.start.line - - self._csnippet.backspace(-self._vstate.moved.col) - # Replace - self._vb.replace_lines(sline, sline + dlines, - self._csnippet._current_text) - - ct_end = self._ctab.abs_end - vim.current.window.cursor = ct_end.line +1, ct_end.col - - self._vstate.update() + self._backspace(-self._vstate.moved.col) else: line = vim.current.line @@ -323,7 +312,6 @@ class SnippetManager(object): self._vstate.pos.col] self._chars_entered(chars) - self._expect_move_wo_change = False def entered_insert_mode(self): @@ -332,17 +320,24 @@ class SnippetManager(object): self.reset() def _chars_entered(self, chars): - sline = self._csnippet.abs_start.line - dlines = self._csnippet.end.line - self._csnippet.start.line - if self._csnippet._tab_selected: self._ctab.current_text = chars self._csnippet._tab_selected = False else: self._ctab.current_text += chars + self._update_vim_buffer() + + def _backspace(self, count): + self._ctab.current_text = self._ctab.current_text[:-count] + self._update_vim_buffer() + + def _update_vim_buffer(self): + sline = self._csnippet.abs_start.line + dlines = self._csnippet.end.line - self._csnippet.start.line + self._csnippet.update() - + # Replace dlines += self._vstate.moved.line self._vb.replace_lines(sline, sline + dlines, @@ -352,7 +347,7 @@ class SnippetManager(object): self._vstate.update() - def backspace(self): + def backspace_while_selected(self): # BS was called in select mode if self._csnippet and self._csnippet.tab_selected: