From df62b246a055548a092dba45d6db1dc6b23a0fdc Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 23 Aug 2012 20:28:29 +0400 Subject: [PATCH] IDEA-90499 Ctrl+Backspace deletes delimiters instead of whitespaces only and leads to SyntaxErrors in code --- .../editor/actions/EditorActionUtil.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java index b01d2bef3d8d..a7a047627dea 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java @@ -44,6 +44,7 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.EditorPopupHandler; +import gnu.trove.TIntHashSet; import java.awt.*; import java.awt.event.MouseEvent; @@ -64,16 +65,23 @@ public class EditorActionUtil { * expect the caret to be located at the near future. */ public static final Key EXPECTED_CARET_OFFSET = Key.create("expectedEditorOffset"); - - protected static final Object EDIT_COMMAND_GROUP = Key.create("EditGroup"); - public static final Object DELETE_COMMAND_GROUP = Key.create("DeleteGroup"); + + protected static final Object EDIT_COMMAND_GROUP = Key.create("EditGroup"); + public static final Object DELETE_COMMAND_GROUP = Key.create("DeleteGroup"); + + private static final TIntHashSet SPECIAL_NON_ID_SYMBOLS = new TIntHashSet(); + + static { + SPECIAL_NON_ID_SYMBOLS.add('\''); + SPECIAL_NON_ID_SYMBOLS.add('\"'); + } private EditorActionUtil() { } /** * Tries to change given editor's viewport position in vertical dimension by the given number of visual lines. - * + * * @param editor target editor which viewport position should be changed * @param lineShift defines viewport position's vertical change length * @param columnShift defines viewport position's horizontal change length @@ -94,7 +102,7 @@ public class EditorActionUtil { if (!moveCaret) { return; } - + Rectangle viewRectangle = editor.getScrollingModel().getVisibleArea(); int lineNumber = editor.getCaretModel().getVisualPosition().line; if (viewRectangle != null) { @@ -220,16 +228,26 @@ public class EditorActionUtil { final boolean firstIsIdentifierPart = Character.isJavaIdentifierPart(prev); final boolean secondIsIdentifierPart = Character.isJavaIdentifierPart(current); - if (!firstIsIdentifierPart && secondIsIdentifierPart) { + if (!firstIsIdentifierPart && secondIsIdentifierPart && !SPECIAL_NON_ID_SYMBOLS.contains(prev)) { return true; } if (isCamel && firstIsIdentifierPart && secondIsIdentifierPart && isHumpBound(text, offset, true)) { return true; } - - return (Character.isWhitespace(prev) || firstIsIdentifierPart) && - !Character.isWhitespace(current) && !secondIsIdentifierPart; + + if (Character.isWhitespace(current)) { + return false; + } + else if (Character.isWhitespace(prev)) { + return true; + } + else if (SPECIAL_NON_ID_SYMBOLS.contains(current)) { + return false; + } + else { + return firstIsIdentifierPart && !secondIsIdentifierPart; + } } private static boolean isLowerCaseOrDigit(char c) {