From 461e81d6a2ffed4a6082ede80881ed9c7b9da3ac Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 20:49:32 +0100 Subject: [PATCH 1/4] Added stricter test case that show the problem and implement fixes for them --- plugin/UltiSnips/__init__.py | 4 ++-- test.py | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 9b98c27..fdc9dc9 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -694,8 +694,8 @@ 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) + self._backspace(self._vstate.ppos.col-len(lline)) + self._chars_entered('\n' + cline[:len(cline)-(len(self._vstate.last_line)-self._vstate.ppos.col)], 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..60720bb 100755 --- a/test.py +++ b/test.py @@ -226,6 +226,43 @@ class MultilineExpandWithFormatoptionsOn_ExceptCorrectResult(_VimTest): def _options_off(self): self.send(":set tw=0\n") +class MultilineExpandWithFormatoptionsOnTextAfter_ExceptCorrectResult(_VimTest): + """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""" + def _options_on(self): + self.send(":set tw=20\n") + def _options_off(self): + self.send(":set tw=0\n") + +class MultilineExpandWithFormatoptionsWrapOnLongWord_ExceptCorrectResult(_VimTest): + """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""" + + def _options_on(self): + self.send(":set tw=20\n") + def _options_off(self): + self.send(":set tw=0\n") ############ # TabStops # From 70ba6f0083265b98a492677832d842eca09d7a9f Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 20:54:16 +0100 Subject: [PATCH 2/4] Added another test case that encloses the snippet --- test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test.py b/test.py index 60720bb..cc2f8f0 100755 --- a/test.py +++ b/test.py @@ -217,6 +217,23 @@ class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest): wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts" keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!" + +class MultilineExpandWithFormatoptionsOnTextBeforeAndAfter_ExceptCorrectResult(_VimTest): + 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""" + + def _options_on(self): + self.send(":set tw=20\n") + def _options_off(self): + self.send(":set tw=0\n") + class MultilineExpandWithFormatoptionsOn_ExceptCorrectResult(_VimTest): snippets = ("test", "${1:longer expand}\n$0") keys = "test" + EX + "This is a longer text that should wrap" From 91520a21602d1427027a6b6d1d3ba7755d78bff0 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 20:58:43 +0100 Subject: [PATCH 3/4] Refactored test cases --- test.py | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/test.py b/test.py index cc2f8f0..3b1789f 100755 --- a/test.py +++ b/test.py @@ -217,8 +217,21 @@ class MultilineExpandTestTyping_ExceptCorrectResult(_VimTest): wanted = "Wie Hallo Welt!\nUnd Wie gehtsHuiui! gehts" keys = "Wie hallo gehts" + ESC + "bhi" + EX + "Huiui!" +######################## +# 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 MultilineExpandWithFormatoptionsOnTextBeforeAndAfter_ExceptCorrectResult(_VimTest): +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 = \ @@ -229,21 +242,8 @@ startThis is a longer text that should wrapend""" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") -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" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") - -class MultilineExpandWithFormatoptionsOnTextAfter_ExceptCorrectResult(_VimTest): +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 " @@ -259,12 +259,8 @@ snippet that should wrap properly and the mirror below should work as wellend""" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") -class MultilineExpandWithFormatoptionsWrapOnLongWord_ExceptCorrectResult(_VimTest): +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") @@ -276,11 +272,6 @@ startThis is a longersnippet that should wrap properlyend""" - def _options_on(self): - self.send(":set tw=20\n") - def _options_off(self): - self.send(":set tw=0\n") - ############ # TabStops # ############ From 57cf2790cbe7fa8c62166406a2f2e1fdd72a157b Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sun, 20 Feb 2011 21:16:56 +0100 Subject: [PATCH 4/4] Refactored fix for better understandability --- plugin/UltiSnips/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index fdc9dc9..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(self._vstate.ppos.col-len(lline)) - self._chars_entered('\n' + cline[:len(cline)-(len(self._vstate.last_line)-self._vstate.ppos.col)], 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]