diff --git a/pythonx/UltiSnips/text_objects/_visual.py b/pythonx/UltiSnips/text_objects/_visual.py index 143b30f..0be64b3 100644 --- a/pythonx/UltiSnips/text_objects/_visual.py +++ b/pythonx/UltiSnips/text_objects/_visual.py @@ -42,11 +42,7 @@ class Visual(NoneditableTextObject, TextObjectTransformation): def _update(self, done): if self._mode == 'v': # Normal selection. - # Remove last character when selection mode is 'exclusive' - if _vim.eval('&selection') == 'exclusive': - text = self._text[:-1] - else: - text = self._text + text = self._text else: # Block selection or line selection. text_before = _vim.buf[self.start.line][:self.start.col] indent = _REPLACE_NON_WS.sub(' ', text_before) diff --git a/pythonx/UltiSnips/vim_state.py b/pythonx/UltiSnips/vim_state.py index 9ebe4e9..af414be 100644 --- a/pythonx/UltiSnips/vim_state.py +++ b/pythonx/UltiSnips/vim_state.py @@ -126,6 +126,12 @@ class VisualContentPreserver(object): ec = byte2col(el, ebyte - 1) self._mode = _vim.eval('visualmode()') + # When 'selection' is 'exclusive', the > mark is one column behind the + # actual content being copied, but never before the < mark. + if _vim.eval('&selection') == 'exclusive': + if not (sl == el and sbyte == ebyte): + ec -= 1 + _vim_line_with_eol = lambda ln: _vim.buf[ln] + '\n' if sl == el: diff --git a/test/test_Visual.py b/test/test_Visual.py index d6d9d8a..fd34d2b 100644 --- a/test/test_Visual.py +++ b/test/test_Visual.py @@ -1,9 +1,6 @@ from test.vim_test_case import VimTestCase as _VimTest from test.constant import * -# ${VISUAL} {{{# - - class Visual_NoVisualSelection_Ignore(_VimTest): snippets = ('test', 'h${VISUAL}b') keys = 'test' + EX + 'abc' @@ -15,6 +12,18 @@ class Visual_SelectOneWord(_VimTest): keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX wanted = 'hblablubb' +class Visual_SelectOneWordInclusive(_VimTest): + snippets = ('test', 'h${VISUAL}b', '', 'i') + keys = 'xxxyyyyxxx' + ESC + '4|vlll' + EX + 'test' + EX + wanted = 'xxxhyyyybxxx' + +class Visual_SelectOneWordExclusive(_VimTest): + snippets = ('test', 'h${VISUAL}b', '', 'i') + keys = 'xxxyyyyxxx' + ESC + '4|vlll' + EX + 'test' + EX + wanted = 'xxxhyyybyxxx' + + def _extra_vim_config(self, vim_config): + vim_config.append('set selection=exclusive') class Visual_SelectOneWord_ProblemAfterTab(_VimTest): snippets = ('test', 'h${VISUAL}b', '', 'i') @@ -200,5 +209,3 @@ class VisualTransformation_InDefaultText_LineSelect_Overwrite(_VimTest): keys = 'hello\nnice\nworld' + ESC + 'Vkk' + \ EX + 'test' + EX + 'jup' + JF + 'hi' wanted = 'hjupbhi' - -# End: ${VISUAL} #}}}