mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not search for element on previous line
fixed PY-8595 Unwrap/Remove action should not be available with caret/selection after the statement with caret on empty line
This commit is contained in:
@@ -56,7 +56,7 @@ public abstract class TypeIntention implements IntentionAction {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static PyExpression getProblemElement(PsiElement elementAt) {
|
||||
protected static PyExpression getProblemElement(@Nullable PsiElement elementAt) {
|
||||
PyExpression problemElement = PsiTreeUtil.getParentOfType(elementAt, PyNamedParameter.class, PyReferenceExpression.class);
|
||||
if (problemElement == null) return null;
|
||||
if (problemElement instanceof PyQualifiedExpression) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.lang.ASTFactory;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
@@ -1168,11 +1169,17 @@ public class PyUtil {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
while (caretOffset > 0 && element instanceof PsiWhiteSpace) {
|
||||
int lineStartOffset = 0;
|
||||
final Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
|
||||
if (document != null) {
|
||||
int lineNumber = document.getLineNumber(caretOffset);
|
||||
lineStartOffset = document.getLineStartOffset(lineNumber);
|
||||
}
|
||||
while (caretOffset >= lineStartOffset && element instanceof PsiWhiteSpace) {
|
||||
caretOffset--;
|
||||
element = psiFile.findElementAt(caretOffset);
|
||||
}
|
||||
return element;
|
||||
return element instanceof PsiWhiteSpace ? null : element;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class PyChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement findTargetMember(PsiElement element) {
|
||||
public PsiElement findTargetMember(@Nullable PsiElement element) {
|
||||
final PyCallExpression callExpression = PsiTreeUtil.getParentOfType(element, PyCallExpression.class);
|
||||
if (callExpression != null) {
|
||||
return callExpression.resolveCalleeFunction(PyResolveContext.defaultContext());
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
while True:
|
||||
x = 1
|
||||
<caret>
|
||||
@@ -42,6 +42,7 @@ public class PyUnwrapperTest extends PyTestCase {
|
||||
public void testWithUnwrap() throws Throwable {doTest(LanguageLevel.PYTHON32);}
|
||||
|
||||
public void testEndOfStatementUnwrap() throws Throwable {doTest();}
|
||||
public void testEndOfStatementNextLineUnwrap() throws Throwable {doNegativeTest();}
|
||||
|
||||
private void doTest() {
|
||||
doTest(0);
|
||||
|
||||
Reference in New Issue
Block a user