From e2da5031c753725c5e08d0949db2d27333a38ba2 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Tue, 26 Mar 2013 13:02:16 +0400 Subject: [PATCH] fixed PY-9260 Unwrap/Remove action is not available inside statement with caret on indented space --- python/src/com/jetbrains/python/psi/PyUtil.java | 10 +++++++++- .../unwrap/whitespaceAtCaretUnwrap_after.py | 2 ++ .../unwrap/whitespaceAtCaretUnwrap_before.py | 4 ++++ .../jetbrains/python/refactoring/PyUnwrapperTest.java | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_after.py create mode 100644 python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_before.py diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index 6db77aa84a54..a55b052ba135 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -1177,7 +1177,7 @@ public class PyUtil { } @Nullable - public static PsiElement findNonWhitespaceAtOffset(PsiFile psiFile, int caretOffset) { + public static PsiElement findPrevNonWhitespaceAtOffset(PsiFile psiFile, int caretOffset) { PsiElement element = psiFile.findElementAt(caretOffset); if (element == null) { return null; @@ -1195,6 +1195,14 @@ public class PyUtil { return element instanceof PsiWhiteSpace ? null : element; } + @Nullable + public static PsiElement findNonWhitespaceAtOffset(PsiFile psiFile, int caretOffset) { + PsiElement element = findNextNonWhitespaceAtOffset(psiFile, caretOffset); + if (element == null) + element = findPrevNonWhitespaceAtOffset(psiFile, caretOffset); + return element; + } + @Nullable public static PsiElement findNextNonWhitespaceAtOffset(@NotNull final PsiFile psiFile, int caretOffset) { PsiElement element = psiFile.findElementAt(caretOffset); diff --git a/python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_after.py b/python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_after.py new file mode 100644 index 000000000000..474b42e9c37a --- /dev/null +++ b/python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_after.py @@ -0,0 +1,2 @@ +print 1 +print 2 diff --git a/python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_before.py b/python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_before.py new file mode 100644 index 000000000000..b4d4feb8fba2 --- /dev/null +++ b/python/testData/refactoring/unwrap/whitespaceAtCaretUnwrap_before.py @@ -0,0 +1,4 @@ + +if True: + print 1 + print 2 \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyUnwrapperTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyUnwrapperTest.java index 7c7b72371fab..73dcd4d0c7fb 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyUnwrapperTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyUnwrapperTest.java @@ -50,6 +50,8 @@ public class PyUnwrapperTest extends PyTestCase { public void testIfInElifBranchUnwrap() throws Throwable {doNegativeTest(PyBundle.message("unwrap.if"));} + public void testWhitespaceAtCaretUnwrap() throws Throwable {doTest();} + private void doTest() { doTest(0); }