diff --git a/python/src/com/jetbrains/python/editor/PythonBackspaceHandler.java b/python/src/com/jetbrains/python/editor/PythonBackspaceHandler.java index 256cc5605dc6..2c72fd431e29 100644 --- a/python/src/com/jetbrains/python/editor/PythonBackspaceHandler.java +++ b/python/src/com/jetbrains/python/editor/PythonBackspaceHandler.java @@ -23,7 +23,8 @@ public class PythonBackspaceHandler extends BackspaceHandlerDelegate { if (myTargetPosition != null) { // Remove all the following spaces before moving to targetPosition final int offset = editor.getCaretModel().getOffset(); - editor.getSelectionModel().setSelection(offset - editor.getCaretModel().getVisualPosition().column + myTargetPosition.column, offset); + final int targetOffset = editor.logicalPositionToOffset(myTargetPosition); + editor.getSelectionModel().setSelection(targetOffset, offset); EditorModificationUtil.deleteSelectedText(editor); editor.getCaretModel().moveToLogicalPosition(myTargetPosition); myTargetPosition = null; diff --git a/python/testData/editing/py254.py b/python/testData/editing/py254.after.py similarity index 100% rename from python/testData/editing/py254.py rename to python/testData/editing/py254.after.py diff --git a/python/testData/editing/py254.before.py b/python/testData/editing/py254.before.py new file mode 100644 index 000000000000..fe08bad30ded --- /dev/null +++ b/python/testData/editing/py254.before.py @@ -0,0 +1,7 @@ + +class Foo(object): + def foo(bar): + pass + + def bar(foo): + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyEditingTest.java b/python/testSrc/com/jetbrains/python/PyEditingTest.java index c6bd2234b35d..34f082a2b5ad 100644 --- a/python/testSrc/com/jetbrains/python/PyEditingTest.java +++ b/python/testSrc/com/jetbrains/python/PyEditingTest.java @@ -12,8 +12,6 @@ import com.intellij.openapi.util.Computable; import com.intellij.psi.PsiFile; import com.jetbrains.python.fixtures.PyLightFixtureTestCase; -import java.io.IOException; - /** * @author yole */ @@ -62,27 +60,27 @@ public class PyEditingTest extends PyLightFixtureTestCase { assertEquals("''", doTestTyping("''", 1, '\'')); } - public void testGreedyBackspace() throws Exception { // PY-254 - myFixture.configureByFile("/editing/py254.py"); - myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 8)); - CommandProcessor.getInstance().executeCommand(myFixture.getProject(), new Runnable() { - public void run() { - myFixture.performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE); - } - }, "", null); - // this should not modify the text, so we can check against the same file - myFixture.checkResultByFile("/editing/py254.py", true); + public void testGreedyBackspace() { // PY-254 + doTestBackspace("py254", new LogicalPosition(4, 8)); } - public void testUnindentBackspace() throws Exception { // PY-853 - myFixture.configureByFile("/editing/smartUnindent.before.py"); - myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 4)); + public void testUnindentBackspace() { // PY-853 + doTestBackspace("smartUnindent", new LogicalPosition(1, 4)); + } + + public void testUnindentTab() { // PY-1270 + doTestBackspace("unindentTab", new LogicalPosition(4, 4)); + } + + private void doTestBackspace(final String fileName, final LogicalPosition pos) { + myFixture.configureByFile("/editing/" + fileName + ".before.py"); + myFixture.getEditor().getCaretModel().moveToLogicalPosition(pos); CommandProcessor.getInstance().executeCommand(myFixture.getProject(), new Runnable() { public void run() { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE); } }, "", null); - myFixture.checkResultByFile("/editing/smartUnindent.after.py", true); + myFixture.checkResultByFile("/editing/" + fileName + ".after.py", true); } public void testUncommentWithSpace() throws Exception { // PY-980