actions: do not break cursor on single line change

This commit is contained in:
Stanislav Seletskiy 2016-04-27 22:29:50 +06:00
parent 6cd168c5b4
commit aaa89bf0d6
2 changed files with 24 additions and 8 deletions

View File

@ -163,12 +163,12 @@ class VimBufferProxy(_vim.VimBuffer):
for line_number in range(start, end): for line_number in range(start, end):
if line_number < 0: if line_number < 0:
line_number = len(self._buffer) + line_number line_number = len(self._buffer) + line_number
yield ('D', line_number, 0, self._buffer[line_number]) yield ('D', line_number, 0, self._buffer[line_number], True)
if start < 0: if start < 0:
start = len(self._buffer) + start start = len(self._buffer) + start
for line_number in range(0, len(new_value)): for line_number in range(0, len(new_value)):
yield ('I', start+line_number, 0, new_value[line_number]) yield ('I', start+line_number, 0, new_value[line_number], True)
def _get_line_diff(self, line_number, before, after): def _get_line_diff(self, line_number, before, after):
""" """
@ -189,25 +189,30 @@ class VimBufferProxy(_vim.VimBuffer):
if not self._snippets_stack: if not self._snippets_stack:
return return
line_number = change[1] change_type, line_number, column_number, change_text = change[0:4]
column_number = change[2]
line_before = line_number <= self._snippets_stack[0]._start.line line_before = line_number <= self._snippets_stack[0]._start.line
column_before = column_number <= self._snippets_stack[0]._start.col column_before = column_number <= self._snippets_stack[0]._start.col
if line_before and column_before: if line_before and column_before:
direction = 1 direction = 1
if change[0] == 'D': if change_type == 'D':
direction = -1 direction = -1
diff = Position(direction, 0)
if len(change) != 5:
diff = Position(0, direction * len(change_text))
print(change, diff)
self._snippets_stack[0]._move( self._snippets_stack[0]._move(
Position(line_number, 0), Position(line_number, column_number),
Position(direction, 0) diff
) )
else: else:
if line_number > self._snippets_stack[0]._end.line: if line_number > self._snippets_stack[0]._end.line:
return return
if column_number >= self._snippets_stack[0]._end.col: if column_number >= self._snippets_stack[0]._end.col:
return return
self._snippets_stack[0]._do_edit(change) self._snippets_stack[0]._do_edit(change[0:4])
def _disable_edits(self): def _disable_edits(self):
""" """

View File

@ -368,3 +368,14 @@ class SnippetActions_PostActionModifiesLineAfterSnippet(_VimTest):
"""} """}
keys = '\n3' + ARR_U + 'a' + EX + '1' + JF + '2' keys = '\n3' + ARR_U + 'a' + EX + '1' + JF + '2'
wanted = '1: 1\n2' wanted = '1: 1\n2'
class SnippetActions_DoNotBreakCursorOnSingleLikeChange(_VimTest):
files = { 'us/all.snippets': r"""
post_expand "snip.buffer[snip.snippet_end[0]] = 'def'; snip.cursor.preserve()"
snippet a "desc"
asd
endsnippet
"""}
keys = 'a' + EX + '123'
wanted = 'def123'