From b5165a7e498b87cb53e6a1b8afd6af1f0468390d Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 2 Oct 2013 20:38:30 +0400 Subject: [PATCH] fixed PY-10995 Wrapping on right margin deletes code with slashes at the end of miltiline statements. If we didn't process auto-formatted events from document - document could be broken by replacement. Do not insert replacement string to the broken textrange --- python/testData/wrap/wrapRightMargin.after.py | 4 ++++ python/testData/wrap/wrapRightMargin.py | 3 +++ .../com/jetbrains/python/PyWrapTest.java | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 python/testData/wrap/wrapRightMargin.after.py create mode 100644 python/testData/wrap/wrapRightMargin.py diff --git a/python/testData/wrap/wrapRightMargin.after.py b/python/testData/wrap/wrapRightMargin.after.py new file mode 100644 index 000000000000..b7ed9d5c2e6c --- /dev/null +++ b/python/testData/wrap/wrapRightMargin.after.py @@ -0,0 +1,4 @@ +def do_stuff(): + another_long_variable = a_really_long_function_name_with_parameters(12, + this_is_the_first_param=23, + this_is_the_second=45).do_more_stuff_to_the_result() diff --git a/python/testData/wrap/wrapRightMargin.py b/python/testData/wrap/wrapRightMargin.py new file mode 100644 index 000000000000..5d84299ddf2b --- /dev/null +++ b/python/testData/wrap/wrapRightMargin.py @@ -0,0 +1,3 @@ +def do_stuff(): + another_long_variable = a_really_long_function_name_with_parameters(12, + this_is_the_first_param=23, this_is_the_second=45).do_more_stuff_to_the_result() diff --git a/python/testSrc/com/jetbrains/python/PyWrapTest.java b/python/testSrc/com/jetbrains/python/PyWrapTest.java index 861d1b56d229..a8150de2b676 100644 --- a/python/testSrc/com/jetbrains/python/PyWrapTest.java +++ b/python/testSrc/com/jetbrains/python/PyWrapTest.java @@ -49,6 +49,28 @@ public class PyWrapTest extends PyTestCase { doTest(" AND field"); } + + public void testWrapRightMargin() { + final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings(); + int oldValue = settings.RIGHT_MARGIN; + boolean oldMarginValue = settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN; + settings.RIGHT_MARGIN = 100; + settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = true; + try { + final String testName = "wrap/" + getTestName(true); + myFixture.configureByFile(testName + ".py"); + for (int i = 0; i != 45; ++i) { + myFixture.type(' '); + } + myFixture.checkResultByFile(testName + ".after.py"); + } + finally { + settings.RIGHT_MARGIN = oldValue; + settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = oldMarginValue; + } + + } + private void doTest(final String textToType) { myFixture.configureByFile("wrap/" + getTestName(false) + ".py"); myFixture.type(textToType);