diff --git a/pylintrc b/pylintrc index d52bb17..5790281 100644 --- a/pylintrc +++ b/pylintrc @@ -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}" diff --git a/pythonx/UltiSnips/text_objects/_visual.py b/pythonx/UltiSnips/text_objects/_visual.py index b83db9c..af5ca4e 100644 --- a/pythonx/UltiSnips/text_objects/_visual.py +++ b/pythonx/UltiSnips/text_objects/_visual.py @@ -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) diff --git a/test.py b/test.py index 0238e47..26e8628 100755 --- a/test.py +++ b/test.py @@ -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")