From 1be8e048383e3fcd41e215b2065811f4a8bbff56 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Tue, 25 Feb 2014 18:53:06 +0400 Subject: [PATCH] IDEA-121057 Multiple Carets: Alt-N works in "whole word" mode if the whole word is initially selected --- .../actions/SelectNextOccurrenceAction.java | 13 +++------ .../SelectUnselectOccurrenceActionsTest.java | 28 ++++--------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java b/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java index 35e34a8a1f2e..81a7851da874 100644 --- a/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java @@ -58,7 +58,7 @@ public class SelectNextOccurrenceAction extends EditorAction { caret.getOffset(), SelectWordUtil.JAVA_IDENTIFIER_PART_CONDITION); boolean notFoundPreviously = getAndResetNotFoundStatus(editor); - Boolean wholeWordSearch = isWholeWordSearch(editor); + boolean wholeWordSearch = isWholeWordSearch(editor); if (caret.hasSelection()) { Project project = editor.getProject(); String selectedText = caret.getSelectedText(); @@ -67,12 +67,6 @@ public class SelectNextOccurrenceAction extends EditorAction { } FindManager findManager = FindManager.getInstance(project); - if (wholeWordSearch == null) { - wholeWordSearch = wordSelectionRange != null - && wordSelectionRange.getStartOffset() == caret.getSelectionStart() - && wordSelectionRange.getEndOffset() == caret.getSelectionEnd(); - setWholeWordSearch(editor, wholeWordSearch); - } FindModel model = new FindModel(); model.setStringToFind(caret.getSelectedText()); model.setCaseSensitive(true); @@ -137,11 +131,12 @@ public class SelectNextOccurrenceAction extends EditorAction { editor.putUserData(NOT_FOUND, Boolean.TRUE); } - private static Boolean isWholeWordSearch(Editor editor) { + private static boolean isWholeWordSearch(Editor editor) { if (!isRepeatedActionInvocation()) { editor.putUserData(WHOLE_WORDS, null); } - return editor.getUserData(WHOLE_WORDS); + Boolean value = editor.getUserData(WHOLE_WORDS); + return value != null; } private static void setWholeWordSearch(Editor editor, boolean isWholeWordSearch) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java index 50f8ca0e6f3b..90a82e972379 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java @@ -58,6 +58,10 @@ public class SelectUnselectOccurrenceActionsTest extends LightPlatformCodeInsigh checkResult("some text\n" + "some texts\n" + "another text here"); + executeAction(); + checkResult("some text\n" + + "some texts\n" + + "another text here"); assertEquals(0, hintCount); } @@ -67,34 +71,29 @@ public class SelectUnselectOccurrenceActionsTest extends LightPlatformCodeInsigh "another text here"); executeAction(); checkResult("some text\n" + - "some texts\n" + - "another text here"); + "some texts\n" + + "another text here"); assertEquals(0, hintCount); } public void testShowingHint() throws Exception { init("some text\n" + - "some texts\n" + "another text here"); executeAction(); assertEquals(1, hintCount); checkResult("some text\n" + - "some texts\n" + "another text here"); executeAction(); assertEquals(1, hintCount); checkResult("some text\n" + - "some texts\n" + "another text here"); } public void testRevert() throws Exception { init("some text\n" + - "some texts\n" + "another text here"); executeReverseAction(); checkResult("some text\n" + - "some texts\n" + "another text here"); assertEquals(0, hintCount); } @@ -141,21 +140,6 @@ public class SelectUnselectOccurrenceActionsTest extends LightPlatformCodeInsigh assertEquals(0, hintCount); } - public void testWholeWordinessIsRememberedAtStart() throws Exception { - init("some texts\n" + - "another text\n" + - "some other texts"); - executeAction(); - checkResult("some texts\n" + - "another text\n" + - "some other texts"); - executeAction(); - checkResult("some texts\n" + - "another text\n" + - "some other texts"); - assertEquals(0, hintCount); - } - public void testOccurrenceInCollapsedRegion() throws Exception { init("normal line\n" + "collapsed line");