A first attempt to add the feature to backspace a default text away
This commit is contained in:
parent
4261a6d17a
commit
8c8f3b9769
@ -579,6 +579,9 @@ class SnippetInstance(TextObject):
|
|||||||
return self._cts
|
return self._cts
|
||||||
|
|
||||||
def backspace(self,count, previous_cp):
|
def backspace(self,count, previous_cp):
|
||||||
|
debug("In backspace")
|
||||||
|
debug("count: %s" % (count))
|
||||||
|
|
||||||
cts = self._tabstops[self._cts]
|
cts = self._tabstops[self._cts]
|
||||||
cts.current_text = cts.current_text[:-count]
|
cts.current_text = cts.current_text[:-count]
|
||||||
|
|
||||||
@ -811,6 +814,8 @@ class SnippetManager(object):
|
|||||||
self._current_snippets.pop()
|
self._current_snippets.pop()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
# else:
|
||||||
|
# vim.command(":au CursorMoved * py PySnipSnippets.normal_mode_moved()")
|
||||||
|
|
||||||
self._vstate.update()
|
self._vstate.update()
|
||||||
self._accept_input = True
|
self._accept_input = True
|
||||||
@ -859,6 +864,7 @@ class SnippetManager(object):
|
|||||||
if s is not None:
|
if s is not None:
|
||||||
self._current_snippets.append(s)
|
self._current_snippets.append(s)
|
||||||
self._accept_input = True
|
self._accept_input = True
|
||||||
|
# vim.command(":au CursorMoved * py PySnipSnippets.normal_mode_moved()")
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -922,6 +928,8 @@ class SnippetManager(object):
|
|||||||
self._expect_move_wo_change = False
|
self._expect_move_wo_change = False
|
||||||
|
|
||||||
def entered_insert_mode(self):
|
def entered_insert_mode(self):
|
||||||
|
debug("Entered insert mode")
|
||||||
|
|
||||||
self._vstate.update()
|
self._vstate.update()
|
||||||
debug("self._vstate.has_moved: %s" % (self._vstate.has_moved))
|
debug("self._vstate.has_moved: %s" % (self._vstate.has_moved))
|
||||||
if len(self._current_snippets) and \
|
if len(self._current_snippets) and \
|
||||||
@ -930,6 +938,19 @@ class SnippetManager(object):
|
|||||||
|
|
||||||
self._current_snippets = []
|
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()
|
PySnipSnippets = SnippetManager()
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ inoremap <Tab> <C-R>=PyVimSnips_ExpandSnippet()<cr>
|
|||||||
snoremap <Tab> <Esc>:call PyVimSnips_ExpandSnippet()<cr>
|
snoremap <Tab> <Esc>:call PyVimSnips_ExpandSnippet()<cr>
|
||||||
inoremap <S-Tab> <C-R>=PyVimSnips_JumpBackwards()<cr>
|
inoremap <S-Tab> <C-R>=PyVimSnips_JumpBackwards()<cr>
|
||||||
snoremap <S-Tab> <Esc>:call 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 CursorMovedI * py PySnipSnippets.cursor_moved()
|
||||||
au InsertEnter * py PySnipSnippets.entered_insert_mode()
|
au InsertEnter * py PySnipSnippets.entered_insert_mode()
|
||||||
|
19
test.py
19
test.py
@ -172,6 +172,25 @@ class TabStopEscapingWhenSelectedNoCharTS_ECR(_VimTest):
|
|||||||
keys = "test\t" + ESC + "0ihi"
|
keys = "test\t" + ESC + "0ihi"
|
||||||
wanted = "hisnip "
|
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):
|
class TabStopWithOneChar_ExceptCorrectResult(_VimTest):
|
||||||
snippets = ("hallo", "nothing ${1:i} hups")
|
snippets = ("hallo", "nothing ${1:i} hups")
|
||||||
keys = "hallo\tship"
|
keys = "hallo\tship"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user