A first attempt to add the feature to backspace a default text away

This commit is contained in:
Holger Rapp 2009-07-06 17:44:04 +02:00
parent 4261a6d17a
commit 8c8f3b9769
3 changed files with 41 additions and 0 deletions

View File

@ -579,6 +579,9 @@ class SnippetInstance(TextObject):
return self._cts
def backspace(self,count, previous_cp):
debug("In backspace")
debug("count: %s" % (count))
cts = self._tabstops[self._cts]
cts.current_text = cts.current_text[:-count]
@ -811,6 +814,8 @@ class SnippetManager(object):
self._current_snippets.pop()
return True
# else:
# vim.command(":au CursorMoved * py PySnipSnippets.normal_mode_moved()")
self._vstate.update()
self._accept_input = True
@ -859,6 +864,7 @@ class SnippetManager(object):
if s is not None:
self._current_snippets.append(s)
self._accept_input = True
# vim.command(":au CursorMoved * py PySnipSnippets.normal_mode_moved()")
return True
@ -922,6 +928,8 @@ class SnippetManager(object):
self._expect_move_wo_change = False
def entered_insert_mode(self):
debug("Entered insert mode")
self._vstate.update()
debug("self._vstate.has_moved: %s" % (self._vstate.has_moved))
if len(self._current_snippets) and \
@ -930,6 +938,19 @@ class SnippetManager(object):
self._current_snippets = []
def normal_mode_moved(self):
# BS was called in select mode
if len(self._current_snippets) and \
self._current_snippets[-1].tab_selected and \
self._vstate.buf_changed:
# This only happens when a default value is delted using backspace
vim.command(r'call feedkeys("i")')
cs = self._current_snippets[-1]
cs.chars_entered('', self._vstate)
self._vstate.update()
else:
vim.command(r'call feedkeys("\<BS>")')
PySnipSnippets = SnippetManager()

View File

@ -59,6 +59,7 @@ inoremap <Tab> <C-R>=PyVimSnips_ExpandSnippet()<cr>
snoremap <Tab> <Esc>:call PyVimSnips_ExpandSnippet()<cr>
inoremap <S-Tab> <C-R>=PyVimSnips_JumpBackwards()<cr>
snoremap <S-Tab> <Esc>:call PyVimSnips_JumpBackwards()<cr>
snoremap <BS> <Esc>:py PySnipSnippets.normal_mode_moved()<cr>
au CursorMovedI * py PySnipSnippets.cursor_moved()
au InsertEnter * py PySnipSnippets.entered_insert_mode()

19
test.py
View File

@ -172,6 +172,25 @@ class TabStopEscapingWhenSelectedNoCharTS_ECR(_VimTest):
keys = "test\t" + ESC + "0ihi"
wanted = "hisnip "
class TabStopUsingBackspaceToDeleteDefaultValue_ECR(_VimTest):
snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
keys = "test\t" + BS
wanted = "snip "
class TabStopUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest):
snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
"${1:default} ${2:def}")
keys = "test\t" + BS + "\thi"
wanted = "snip m2 hi"
class TabStopUsingBackspaceToDeleteDefaultValueInSecondTab_ECR(_VimTest):
snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} "
"${1:default} ${2:def}")
keys = "test\thi\t" + BS
wanted = "snip m1 hi "
class TabStopUsingBackspaceToDeleteDefaultValueTypeSomethingThen_ECR(_VimTest):
snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}")
keys = "test\t" + BS + "hallo"
wanted = "snip matched hallo"
class TabStopWithOneChar_ExceptCorrectResult(_VimTest):
snippets = ("hallo", "nothing ${1:i} hups")
keys = "hallo\tship"