diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 9b98c27..9709a90 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -694,8 +694,12 @@ class SnippetManager(object): this_entered = vim.current.line[:self._vstate.pos.col] self._chars_entered('\n' + cline + this_entered, 1) if line_was_shortened and user_didnt_enter_newline: - self._backspace(len(self._vstate.last_line)-len(lline)) - self._chars_entered('\n' + cline, 1) + nchars_deleted_in_lline = self._vstate.ppos.col - len(lline) + self._backspace(nchars_deleted_in_lline) + nchars_wrapped_from_lline_after_cursor = \ + len(self._vstate.last_line) - self._vstate.ppos.col + self._chars_entered('\n' + cline + [:len(cline)-nchars_wrapped_from_lline_after_cursor], 1) else: pentered = lline[self._vstate.ppos.col:] this_entered = vim.current.line[:self._vstate.pos.col] diff --git a/test.py b/test.py index a650c4a..3b1789f 100755 --- a/test.py +++ b/test.py @@ -217,15 +217,60 @@ class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest): wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts" keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!" -class MultilineExpandWithFormatoptionsOn_ExceptCorrectResult(_VimTest): - snippets = ("test", "${1:longer expand}\n$0") - keys = "test" + EX + "This is a longer text that should wrap" - wanted = "This is a longer\ntext that should\nwrap\n" +######################## +# Format options tests # +######################## +class _FormatoptionsBase(_VimTest): def _options_on(self): self.send(":set tw=20\n") def _options_off(self): self.send(":set tw=0\n") +class FOSimple_ExceptCorrectResult(_FormatoptionsBase): + snippets = ("test", "${1:longer expand}\n$0") + keys = "test" + EX + "This is a longer text that should wrap" + wanted = "This is a longer\ntext that should\nwrap\n" + +class FOTextBeforeAndAfter_ExceptCorrectResult(_FormatoptionsBase): + snippets = ("test", "Before${1:longer expand}After\nstart$1end") + keys = "test" + EX + "This is a longer text that should wrap" + wanted = \ +"""BeforeThis is a +longer text that +should wrapAfter +startThis is a +longer text that +should wrapend""" + + +class FOTextAfter_ExceptCorrectResult(_FormatoptionsBase): + """Testcase for lp:719998""" + snippets = ("test", "${1:longer expand}after\nstart$1end") + keys = ("test" + EX + "This is a longer snippet that should wrap properly " + "and the mirror below should work as well") + wanted = \ +"""This is a longer +snippet that should +wrap properly and +the mirror below +should work as wellafter +startThis is a longer +snippet that should +wrap properly and +the mirror below +should work as wellend""" + +class FOWrapOnLongWord_ExceptCorrectResult(_FormatoptionsBase): + """Testcase for lp:719998""" + snippets = ("test", "${1:longer expand}after\nstart$1end") + keys = ("test" + EX + "This is a longersnippet that should wrap properly") + wanted = \ +"""This is a +longersnippet that +should wrap properlyafter +startThis is a +longersnippet that +should wrap properlyend""" ############ # TabStops #