From e3bbf99023372e05a77e6e899ea07a5d74345c44 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Wed, 27 Jun 2012 15:50:50 +0400 Subject: [PATCH] Revert "IDEA-87713 `Ctrl + Backspace` changed behaviour" This reverts commit 720ae9faa5d87b514986aed5dc56d27a1c69ca49. --- .../actions/DeleteToWordStartAction.java | 32 +++-------------- .../LightPlatformCodeInsightTestCase.java | 34 +++++++++---------- .../com/intellij/util/text/CharArrayUtil.java | 10 +++--- 3 files changed, 26 insertions(+), 50 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteToWordStartAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteToWordStartAction.java index 34ceda57714b..d7026415b463 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteToWordStartAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/DeleteToWordStartAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2009 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. @@ -24,15 +24,12 @@ */ package com.intellij.openapi.editor.actions; -import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.util.text.CharArrayUtil; public class DeleteToWordStartAction extends TextComponentEditorAction { public DeleteToWordStartAction() { @@ -48,31 +45,10 @@ public class DeleteToWordStartAction extends TextComponentEditorAction { } private static void deleteToWordStart(Editor editor) { - final CaretModel caretModel = editor.getCaretModel(); - int endOffset = caretModel.getOffset(); - - // The logic is as follows: - // 1. Check are there white-space symbols starting at the current caret position going backwards. Delete them if any; - // 2. Otherwise locate previous word start and delete the text up to it; - // Example: - // 'test string ' -> 'test string' - // 'test string' -> 'test ' - + int endOffset = editor.getCaretModel().getOffset(); + EditorActionUtil.moveCaretToPreviousWord(editor, false); + int startOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); - final SelectionModel selectionModel = editor.getSelectionModel(); - int startOffset = -1; - if (!selectionModel.hasSelection() && !selectionModel.hasBlockSelection()) { - int i = CharArrayUtil.shiftBackward(document.getCharsSequence(), Math.max(0, endOffset - 1), " \t\n"); - if (i >= 0 && i < endOffset - 1) { - startOffset = i + 1; // We need offset of the first white space symbol, not offset of the last non-white space symbol before it. - } - } - - if (startOffset < 0) { - EditorActionUtil.moveCaretToPreviousWord(editor, false); - startOffset = caretModel.getOffset(); - } - document.deleteString(startOffset, endOffset); } } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index 6d3ec85e2459..3edb127b33a7 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -514,69 +514,69 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest } } protected static void backspace() { - executeAction(IdeActions.ACTION_EDITOR_BACKSPACE); + doAction(IdeActions.ACTION_EDITOR_BACKSPACE); } protected static void delete() { - executeAction(IdeActions.ACTION_EDITOR_DELETE); + doAction(IdeActions.ACTION_EDITOR_DELETE); } protected static void home() { - executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START); + doAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START); } protected static void end() { - executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END); + doAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END); } protected static void copy() { - executeAction(IdeActions.ACTION_EDITOR_COPY); + doAction(IdeActions.ACTION_EDITOR_COPY); } protected static void paste() { - executeAction(IdeActions.ACTION_EDITOR_PASTE); + doAction(IdeActions.ACTION_EDITOR_PASTE); } protected static void moveCaretToPreviousWordWithSelection() { - executeAction("EditorPreviousWordWithSelection"); + doAction("EditorPreviousWordWithSelection"); } protected static void moveCaretToNextWordWithSelection() { - executeAction("EditorNextWordWithSelection"); + doAction("EditorNextWordWithSelection"); } protected static void cutLineBackward() { - executeAction("EditorCutLineBackward"); + doAction("EditorCutLineBackward"); } protected static void cutToLineEnd() { - executeAction("EditorCutLineEnd"); + doAction("EditorCutLineEnd"); } protected static void killToWordStart() { - executeAction("EditorKillToWordStart"); + doAction("EditorKillToWordStart"); } protected static void killToWordEnd() { - executeAction("EditorKillToWordEnd"); + doAction("EditorKillToWordEnd"); } protected static void killRegion() { - executeAction("EditorKillRegion"); + doAction("EditorKillRegion"); } protected static void killRingSave() { - executeAction("EditorKillRingSave"); + doAction("EditorKillRingSave"); } protected static void unindent() { - executeAction("EditorUnindentSelection"); + doAction("EditorUnindentSelection"); } protected static void lineComment() { new CommentByLineCommentHandler().invoke(getProject(), getEditor(), getFile()); } - protected static void executeAction(@NotNull final String actionId) { + private static void doAction(@NotNull final String actionId) { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { diff --git a/platform/util/src/com/intellij/util/text/CharArrayUtil.java b/platform/util/src/com/intellij/util/text/CharArrayUtil.java index e5b5c958e4c4..c5244ba4ca7b 100644 --- a/platform/util/src/com/intellij/util/text/CharArrayUtil.java +++ b/platform/util/src/com/intellij/util/text/CharArrayUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2009 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. @@ -198,17 +198,17 @@ public class CharArrayUtil { return shiftForward(new CharArrayCharSequence(buffer), offset, chars); } - public static int shiftBackward(CharSequence buffer, int offset, String charsToSkip) { + public static int shiftBackward(CharSequence buffer, int offset, String chars) { if (offset >= buffer.length()) return offset; while (true) { if (offset < 0) break; char c = buffer.charAt(offset); int i; - for (i = 0; i < charsToSkip.length(); i++) { - if (c == charsToSkip.charAt(i)) break; + for (i = 0; i < chars.length(); i++) { + if (c == chars.charAt(i)) break; } - if (i == charsToSkip.length()) break; + if (i == chars.length()) break; offset--; } return offset;