Dedent visual line selections before using them.

Fixes #217.
This commit is contained in:
Holger Rapp 2014-02-19 21:49:33 +01:00
parent fe2ab12c39
commit 980891c3df
3 changed files with 11 additions and 6 deletions

View File

@ -54,7 +54,7 @@ disable=
output-format=text
# Tells whether to display a full report or only the messages
reports=yes
reports=no
msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}"

View File

@ -6,6 +6,7 @@ selected and insert it here. If there was no text visually selected, this will
be the empty string. """
import re
import textwrap
import UltiSnips._vim as _vim
from UltiSnips.indent_util import IndentUtil
@ -34,21 +35,21 @@ class Visual(NoneditableTextObject, TextObjectTransformation):
TextObjectTransformation.__init__(self, token)
def _update(self, done):
if self._mode != "v":
# Keep the indent for Line/Block Selection
if self._mode == "v": # Normal selection.
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)
iu = IndentUtil()
indent = iu.indent_to_spaces(indent)
indent = iu.spaces_to_indent(indent)
text = ""
for idx, line in enumerate(self._text.splitlines(True)):
for idx, line in enumerate(textwrap.dedent(
self._text).splitlines(True)):
if idx != 0:
text += indent
text += line
text = text[:-1] # Strip final '\n'
else:
text = self._text
text = self._transform(text)
self.overwrite(text)

View File

@ -1734,6 +1734,10 @@ class Visual_LineSelect_CheckIndentWithTS_NoOverwrite(_VimTest):
snippets = ("test", "beg\n\t${0:${VISUAL}}\nend")
keys = "hello\nnice\nworld" + ESC + "Vkk" + EX + "test" + EX
wanted = "beg\n\thello\n\tnice\n\tworld\nend"
class Visual_LineSelect_DedentLine(_VimTest):
snippets = ("if", "if {\n\t${VISUAL}$0\n}")
keys = "if" + EX + "one\n\ttwo\n\tthree" + ESC + ARR_U*2 + "V" + ARR_D + EX + "\tif" + EX
wanted = "if {\n\tif {\n\t\tone\n\t\ttwo\n\t}\n\tthree\n}"
class VisualTransformation_SelectOneWord(_VimTest):
snippets = ("test", r"h${VISUAL/./\U$0\E/g}b")