fix bug when vim option 'selection' is 'exclusive' (#883)
here is a vim option ``selection``. if the value is `exclusive`, the mark `'>` is one more then real visual selection. so var `ebyte` or `ec` must subtract 1. and that is not a windows bug. because gvim on windows sourced `$VIMRUNTIME\mswin.vim` by default. the line 17 of `mswin.vim` execute `:behave mswin` will change option `selection` to `exclusive`. more deailt in issue #863
This commit is contained in:
parent
4eac979888
commit
f4304d59cc
@ -42,11 +42,7 @@ class Visual(NoneditableTextObject, TextObjectTransformation):
|
|||||||
|
|
||||||
def _update(self, done):
|
def _update(self, done):
|
||||||
if self._mode == 'v': # Normal selection.
|
if self._mode == 'v': # Normal selection.
|
||||||
# Remove last character when selection mode is 'exclusive'
|
text = self._text
|
||||||
if _vim.eval('&selection') == 'exclusive':
|
|
||||||
text = self._text[:-1]
|
|
||||||
else:
|
|
||||||
text = self._text
|
|
||||||
else: # Block selection or line selection.
|
else: # Block selection or line selection.
|
||||||
text_before = _vim.buf[self.start.line][:self.start.col]
|
text_before = _vim.buf[self.start.line][:self.start.col]
|
||||||
indent = _REPLACE_NON_WS.sub(' ', text_before)
|
indent = _REPLACE_NON_WS.sub(' ', text_before)
|
||||||
|
@ -126,6 +126,12 @@ class VisualContentPreserver(object):
|
|||||||
ec = byte2col(el, ebyte - 1)
|
ec = byte2col(el, ebyte - 1)
|
||||||
self._mode = _vim.eval('visualmode()')
|
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'
|
_vim_line_with_eol = lambda ln: _vim.buf[ln] + '\n'
|
||||||
|
|
||||||
if sl == el:
|
if sl == el:
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
from test.vim_test_case import VimTestCase as _VimTest
|
from test.vim_test_case import VimTestCase as _VimTest
|
||||||
from test.constant import *
|
from test.constant import *
|
||||||
|
|
||||||
# ${VISUAL} {{{#
|
|
||||||
|
|
||||||
|
|
||||||
class Visual_NoVisualSelection_Ignore(_VimTest):
|
class Visual_NoVisualSelection_Ignore(_VimTest):
|
||||||
snippets = ('test', 'h${VISUAL}b')
|
snippets = ('test', 'h${VISUAL}b')
|
||||||
keys = 'test' + EX + 'abc'
|
keys = 'test' + EX + 'abc'
|
||||||
@ -15,6 +12,18 @@ class Visual_SelectOneWord(_VimTest):
|
|||||||
keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX
|
keys = 'blablub' + ESC + '0v6l' + EX + 'test' + EX
|
||||||
wanted = 'hblablubb'
|
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):
|
class Visual_SelectOneWord_ProblemAfterTab(_VimTest):
|
||||||
snippets = ('test', 'h${VISUAL}b', '', 'i')
|
snippets = ('test', 'h${VISUAL}b', '', 'i')
|
||||||
@ -200,5 +209,3 @@ class VisualTransformation_InDefaultText_LineSelect_Overwrite(_VimTest):
|
|||||||
keys = 'hello\nnice\nworld' + ESC + 'Vkk' + \
|
keys = 'hello\nnice\nworld' + ESC + 'Vkk' + \
|
||||||
EX + 'test' + EX + 'jup' + JF + 'hi'
|
EX + 'test' + EX + 'jup' + JF + 'hi'
|
||||||
wanted = 'hjupbhi'
|
wanted = 'hjupbhi'
|
||||||
|
|
||||||
# End: ${VISUAL} #}}}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user