diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/LanguageCodeStyleSettingsProvider.java b/platform/lang-api/src/com/intellij/psi/codeStyle/LanguageCodeStyleSettingsProvider.java index 71d1ddc3ac4c..3b97016645c2 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/LanguageCodeStyleSettingsProvider.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/LanguageCodeStyleSettingsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,10 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; -import com.intellij.util.ArrayUtil; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Set; @@ -225,6 +223,10 @@ public abstract class LanguageCodeStyleSettingsProvider { return fieldCollector.getCollectedFields(); } + public boolean isIndentBasedLanguageSemantics() { + return false; + } + private final class SupportedFieldCollector implements CodeStyleSettingsCustomizable { private final Set myCollectedFields = new HashSet(); private SettingsType myCurrSettingsType; diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.form b/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.form index 9c73a83ed92a..b69087962ab0 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.form +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.form @@ -1,6 +1,6 @@
- + @@ -10,7 +10,7 @@ - + @@ -33,7 +33,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -51,7 +51,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -88,7 +88,7 @@ - + @@ -97,7 +97,7 @@ - + @@ -135,26 +135,34 @@ - + - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java index daada36ed175..2cabcabf74ad 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,6 +63,7 @@ public class EditorSmartKeysConfigurable extends CompositeConfigurable, C public boolean SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO = false; + public boolean INDENTING_BACKSPACE = false; + public boolean SMART_INDENT_ON_ENTER = true; public boolean INSERT_BRACE_ON_ENTER = true; public boolean INSERT_SCRIPTLET_END_ON_ENTER = true; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/IndentingBackspaceHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/IndentingBackspaceHandler.java new file mode 100644 index 000000000000..f10c13a7740f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/IndentingBackspaceHandler.java @@ -0,0 +1,134 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.editorActions; + +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeStyle.CodeStyleFacade; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider; +import com.intellij.util.text.CharArrayUtil; +import org.jetbrains.annotations.NotNull; + +/** + * Makes Backspace action delete all whitespace till next valid indent position + */ +public class IndentingBackspaceHandler extends BackspaceHandlerDelegate { + private static final Logger LOG = Logger.getInstance(IndentingBackspaceHandler.class); + + @Override + public void beforeCharDeleted(char c, PsiFile file, Editor editor) { + } + + @Override + public boolean charDeleted(char c, PsiFile file, Editor editor) { + if (!CodeInsightSettings.getInstance().INDENTING_BACKSPACE || " \n\t".indexOf(c) == -1) { + return false; + } + LanguageCodeStyleSettingsProvider codeStyleSettingsProvider = LanguageCodeStyleSettingsProvider.forLanguage(file.getLanguage()); + if (codeStyleSettingsProvider != null && codeStyleSettingsProvider.isIndentBasedLanguageSemantics()) { + return false; + } + + Document document = editor.getDocument(); + + int offset = CharArrayUtil.shiftForward(document.getCharsSequence(), editor.getCaretModel().getOffset(), " \t"); + int beforeWhitespaceOffset = CharArrayUtil.shiftBackward(document.getCharsSequence(), offset - 1, " \t") + 1; + LogicalPosition logicalPosition = editor.offsetToLogicalPosition(offset); + int lineStartOffset = document.getLineStartOffset(logicalPosition.line); + if (lineStartOffset < beforeWhitespaceOffset) { + if (c == '\n' && beforeWhitespaceOffset < offset) { + document.deleteString(beforeWhitespaceOffset, offset); + return true; + } + else { + return false; + } + } + + CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(editor.getProject()); + String indent = codeStyleFacade.getLineIndent(document, lineStartOffset); + if (indent == null) { + return false; + } + + int tabSize = getTabSize(codeStyleFacade, document); + int targetColumn = getWidth(indent, tabSize); + + if (logicalPosition.column == targetColumn) { + return false; + } + + if (c == '\n' || logicalPosition.column > targetColumn) { + smartReplace(document, lineStartOffset, offset, indent); + return true; + } + + if (logicalPosition.line == 0) { + return false; + } + + int prevLineStartOffset = document.getLineStartOffset(logicalPosition.line - 1); + int prevLineEndOffset = document.getLineEndOffset(logicalPosition.line - 1); + int targetOffset = CharArrayUtil.shiftBackward(document.getCharsSequence(), prevLineEndOffset - 1, " \t") + 1; + + if (prevLineStartOffset < targetOffset) { + document.deleteString(targetOffset, offset); + } + else { + smartReplace(document, prevLineStartOffset, offset, indent); + } + return true; + } + + private static void smartReplace(Document document, int from, int to, String indent) { + CharSequence text = document.getCharsSequence(); + int prefixLength = 0; + while ((prefixLength + from) < to && prefixLength < indent.length() && text.charAt(prefixLength + from) == indent.charAt(prefixLength)) { + prefixLength++; + } + document.replaceString(from + prefixLength, to, indent.substring(prefixLength)); + } + + private static int getTabSize(@NotNull CodeStyleFacade codeStyleFacade, @NotNull Document document) { + VirtualFile file = FileDocumentManager.getInstance().getFile(document); + FileType fileType = file == null ? null : file.getFileType(); + return codeStyleFacade.getTabSize(fileType); + } + + private static int getWidth(@NotNull String indent, int tabSize) { + int width = 0; + for (int i = 0; i < indent.length(); i++) { + char c = indent.charAt(i); + switch (c) { + case '\t': + width = tabSize * (width / tabSize + 1); + break; + default: + LOG.error("Unexpected whitespace character: " + ((int)c)); + case ' ': + width++; + } + } + return width; + } +} diff --git a/platform/lang-impl/testData/editor/indentingBackspace/atNextLine-after.java b/platform/lang-impl/testData/editor/indentingBackspace/atNextLine-after.java new file mode 100644 index 000000000000..7180cd368c25 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/atNextLine-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/atNextLine.java b/platform/lang-impl/testData/editor/indentingBackspace/atNextLine.java new file mode 100644 index 000000000000..a41b2a20a0b2 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/atNextLine.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/atSameLine-after.java b/platform/lang-impl/testData/editor/indentingBackspace/atSameLine-after.java new file mode 100644 index 000000000000..d91f66f3c590 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/atSameLine-after.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/atSameLine.java b/platform/lang-impl/testData/editor/indentingBackspace/atSameLine.java new file mode 100644 index 000000000000..ff85b46aa743 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/atSameLine.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/atTargetPosition-after.java b/platform/lang-impl/testData/editor/indentingBackspace/atTargetPosition-after.java new file mode 100644 index 000000000000..f0c299c64593 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/atTargetPosition-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/atTargetPosition.java b/platform/lang-impl/testData/editor/indentingBackspace/atTargetPosition.java new file mode 100644 index 000000000000..d91f66f3c590 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/atTargetPosition.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/beforeTargetPosition-after.java b/platform/lang-impl/testData/editor/indentingBackspace/beforeTargetPosition-after.java new file mode 100644 index 000000000000..f0c299c64593 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/beforeTargetPosition-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/beforeTargetPosition.java b/platform/lang-impl/testData/editor/indentingBackspace/beforeTargetPosition.java new file mode 100644 index 000000000000..089b14cff9e4 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/beforeTargetPosition.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText1-after.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText1-after.java new file mode 100644 index 000000000000..7180cd368c25 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText1-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText1.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText1.java new file mode 100644 index 000000000000..14a7793e9c98 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText1.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText2-after.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText2-after.java new file mode 100644 index 000000000000..e8c58612a4db --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText2-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText2.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText2.java new file mode 100644 index 000000000000..35f82262dddd --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText2.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText3-after.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText3-after.java new file mode 100644 index 000000000000..6aa58a6ac8b1 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText3-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText3.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText3.java new file mode 100644 index 000000000000..411d17ea2ad7 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText3.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText4-after.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText4-after.java new file mode 100644 index 000000000000..b77c65948e6f --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText4-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText4.java b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText4.java new file mode 100644 index 000000000000..64073eaac6d8 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/caretAheadOfText4.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/inText-after.java b/platform/lang-impl/testData/editor/indentingBackspace/inText-after.java new file mode 100644 index 000000000000..296c5767689b --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/inText-after.java @@ -0,0 +1,4 @@ +class Foo { + + int fild; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/inText.java b/platform/lang-impl/testData/editor/indentingBackspace/inText.java new file mode 100644 index 000000000000..c02be8a42be4 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/inText.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/inTheMiddle-after.java b/platform/lang-impl/testData/editor/indentingBackspace/inTheMiddle-after.java new file mode 100644 index 000000000000..b66d09789cae --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/inTheMiddle-after.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/inTheMiddle.java b/platform/lang-impl/testData/editor/indentingBackspace/inTheMiddle.java new file mode 100644 index 000000000000..44b977275c46 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/inTheMiddle.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/lastLine-after.java b/platform/lang-impl/testData/editor/indentingBackspace/lastLine-after.java new file mode 100644 index 000000000000..434592750ec7 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/lastLine-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/lastLine.java b/platform/lang-impl/testData/editor/indentingBackspace/lastLine.java new file mode 100644 index 000000000000..688f58dd8c44 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/lastLine.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/multilineSpace-after.java b/platform/lang-impl/testData/editor/indentingBackspace/multilineSpace-after.java new file mode 100644 index 000000000000..cd1c1ebec7a4 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/multilineSpace-after.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/multilineSpace.java b/platform/lang-impl/testData/editor/indentingBackspace/multilineSpace.java new file mode 100644 index 000000000000..221e14bc68a4 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/multilineSpace.java @@ -0,0 +1,5 @@ +class Foo { + + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/plainText-after.txt b/platform/lang-impl/testData/editor/indentingBackspace/plainText-after.txt new file mode 100644 index 000000000000..484f3cd0c17e --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/plainText-after.txt @@ -0,0 +1,2 @@ +line1 +line2 \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/plainText.txt b/platform/lang-impl/testData/editor/indentingBackspace/plainText.txt new file mode 100644 index 000000000000..7cc28e1f8631 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/plainText.txt @@ -0,0 +1,2 @@ +line1 + line2 \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/selection-after.java b/platform/lang-impl/testData/editor/indentingBackspace/selection-after.java new file mode 100644 index 000000000000..c82144a072cf --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/selection-after.java @@ -0,0 +1,4 @@ +class Foo { + + +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/selection.java b/platform/lang-impl/testData/editor/indentingBackspace/selection.java new file mode 100644 index 000000000000..15e6cb90ea77 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/selection.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/targetLineStart-after.java b/platform/lang-impl/testData/editor/indentingBackspace/targetLineStart-after.java new file mode 100644 index 000000000000..f0c299c64593 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/targetLineStart-after.java @@ -0,0 +1,3 @@ +class Foo { + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/targetLineStart.java b/platform/lang-impl/testData/editor/indentingBackspace/targetLineStart.java new file mode 100644 index 000000000000..7fab47e1fe41 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/targetLineStart.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/textStart-after.java b/platform/lang-impl/testData/editor/indentingBackspace/textStart-after.java new file mode 100644 index 000000000000..a02efb5a31f5 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/textStart-after.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/indentingBackspace/textStart.java b/platform/lang-impl/testData/editor/indentingBackspace/textStart.java new file mode 100644 index 000000000000..a02efb5a31f5 --- /dev/null +++ b/platform/lang-impl/testData/editor/indentingBackspace/textStart.java @@ -0,0 +1,4 @@ +class Foo { + + int field; +} \ No newline at end of file diff --git a/platform/lang-impl/testSources/com/intellij/codeInsight/editorActions/IndentingBackspaceHandlerTest.java b/platform/lang-impl/testSources/com/intellij/codeInsight/editorActions/IndentingBackspaceHandlerTest.java new file mode 100644 index 000000000000..979d4fdee197 --- /dev/null +++ b/platform/lang-impl/testSources/com/intellij/codeInsight/editorActions/IndentingBackspaceHandlerTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.editorActions; + +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.testFramework.FileBasedTestCaseHelper; +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@SuppressWarnings("JUnit4AnnotatedMethodInJUnit3TestCase") +@RunWith(com.intellij.testFramework.Parameterized.class) +@TestDataPath("/testData/../../../platform/lang-impl/testData/editor/indentingBackspace/") +public class IndentingBackspaceHandlerTest extends LightPlatformCodeInsightTestCase implements FileBasedTestCaseHelper { + private boolean mySavedConfigurationState; + + @Before + public void enableIndentingBackspace() { + mySavedConfigurationState = CodeInsightSettings.getInstance().INDENTING_BACKSPACE; + CodeInsightSettings.getInstance().INDENTING_BACKSPACE = true; + } + + @After + public void restoreSettings() { + CodeInsightSettings.getInstance().INDENTING_BACKSPACE = mySavedConfigurationState; + } + + @Test + public void testAction() { + new WriteCommandAction(null) { + @Override + protected void run(@NotNull Result result) throws Throwable { + configureByFile(myFileSuffix); + backspace(); + checkResultByFile(myFileSuffix.replace(".", "-after.")); + } + }.execute(); + } + + @Nullable + @Override + public String getFileSuffix(String fileName) { + return fileName.contains("-after.") ? null : fileName; + } +} \ No newline at end of file diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index aa1877f3eebc..aed4eb47ec9e 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -407,6 +407,7 @@ checkbox.smart.indent=Smart indent label.smart.enter=Smart Enter: checkbox.smart.end.on.blank.line=End (on blank line) checkbox.smart.home=Home +checkbox.indenting.backspace=Backspace smart indent group.error.highlighting=Error highlighting editbox.autoreparse.delay.ms=Autoreparse delay (ms): editbox.error.stripe.mark.min.height.pixels=Error stripe mark min height (pixels): diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index aba480580eae..f0a65f78a7ea 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -594,6 +594,8 @@ id="EnterBetweenBracesHandler"/> + + diff --git a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java index 9e7f97db5f8e..32ad8a31b003 100644 --- a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java +++ b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,6 +123,11 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin return PlatformUtils.isPyCharm() ? DisplayPriority.KEY_LANGUAGE_SETTINGS : DisplayPriority.LANGUAGE_SETTINGS; } + @Override + public boolean isIndentBasedLanguageSemantics() { + return true; + } + @SuppressWarnings("FieldCanBeLocal") private static String SPACING_SETTINGS_PREVIEW = "def settings_preview(argument, key=value):\n" + " dict = {1:'a', 2:'b', 3:'c'}\n" +