mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-8567 Unwrap/Remove action is not avalable with caret/selection at the very end of the statement
This commit is contained in:
@@ -2,6 +2,12 @@ package com.jetbrains.python.refactoring.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.unwrap.UnwrapDescriptorBase;
|
||||
import com.intellij.codeInsight.unwrap.Unwrapper;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* user : ktisha
|
||||
@@ -21,4 +27,19 @@ public class PyUnwrapDescriptor extends UnwrapDescriptorBase{
|
||||
new PyWithUnwrapper()
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected PsiElement findTargetElement(Editor editor, PsiFile file) {
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
PsiElement endElement = PyUtil.findNonWhitespaceAtOffset(file, offset);
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
if (selectionModel.hasSelection() && selectionModel.getSelectionStart() < offset) {
|
||||
PsiElement startElement = PyUtil.findNonWhitespaceAtOffset(file, selectionModel.getSelectionStart());
|
||||
if (startElement != null && startElement != endElement && startElement.getTextRange().getEndOffset() == offset) {
|
||||
return startElement;
|
||||
}
|
||||
}
|
||||
return endElement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
x = 1
|
||||
@@ -0,0 +1,2 @@
|
||||
while True:
|
||||
x = 1<caret>
|
||||
@@ -41,6 +41,8 @@ public class PyUnwrapperTest extends PyTestCase {
|
||||
|
||||
public void testWithUnwrap() throws Throwable {doTest(LanguageLevel.PYTHON32);}
|
||||
|
||||
public void testEndOfStatementUnwrap() throws Throwable {doTest();}
|
||||
|
||||
private void doTest() {
|
||||
doTest(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user