Merge pull request #868 from J3soon/fix_visual_V

Fix selection when using ${VISUAL} in line selection mode on Windows.
This commit is contained in:
Stanislav Seletskiy 2017-06-30 14:09:49 +07:00 committed by GitHub
commit 1e40333a50
2 changed files with 8 additions and 10 deletions

View File

@ -15,6 +15,7 @@ from UltiSnips import _vim
from UltiSnips.indent_util import IndentUtil from UltiSnips.indent_util import IndentUtil
from UltiSnips.text_objects._transformation import TextObjectTransformation from UltiSnips.text_objects._transformation import TextObjectTransformation
from UltiSnips.text_objects._base import NoneditableTextObject from UltiSnips.text_objects._base import NoneditableTextObject
import platform
_REPLACE_NON_WS = re.compile(r"[^ \t]") _REPLACE_NON_WS = re.compile(r"[^ \t]")
@ -42,6 +43,10 @@ class Visual(NoneditableTextObject, TextObjectTransformation):
def _update(self, done): def _update(self, done):
if self._mode == 'v': # Normal selection. if self._mode == 'v': # Normal selection.
if platform.system() == 'Windows':
# Remove last character for windows in normal selection.
text = self._text[:-1]
else:
text = self._text 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]

View File

@ -8,7 +8,6 @@ from collections import deque, namedtuple
from UltiSnips import _vim from UltiSnips import _vim
from UltiSnips.compatibility import as_unicode, byte2col from UltiSnips.compatibility import as_unicode, byte2col
from UltiSnips.position import Position from UltiSnips.position import Position
import platform
_Placeholder = namedtuple('_FrozenPlaceholder', ['current_text', 'start', 'end']) _Placeholder = namedtuple('_FrozenPlaceholder', ['current_text', 'start', 'end'])
@ -129,19 +128,13 @@ class VisualContentPreserver(object):
_vim_line_with_eol = lambda ln: _vim.buf[ln] + '\n' _vim_line_with_eol = lambda ln: _vim.buf[ln] + '\n'
# Remove last character for windows
if platform.system() == 'Windows':
add = 0
else:
add = 1
if sl == el: if sl == el:
text = _vim_line_with_eol(sl - 1)[sc:ec + add] text = _vim_line_with_eol(sl - 1)[sc:ec + 1]
else: else:
text = _vim_line_with_eol(sl - 1)[sc:] text = _vim_line_with_eol(sl - 1)[sc:]
for cl in range(sl, el - 1): for cl in range(sl, el - 1):
text += _vim_line_with_eol(cl) text += _vim_line_with_eol(cl)
text += _vim_line_with_eol(el - 1)[:ec + add] text += _vim_line_with_eol(el - 1)[:ec + 1]
self._text = text self._text = text
def conserve_placeholder(self, placeholder): def conserve_placeholder(self, placeholder):