IDEA-137725 Move by word (option-arrow key) is not working in find dialog if regexp option is enabled

This commit is contained in:
Dmitry Batrak
2015-03-26 15:12:29 +03:00
parent 2af4f99331
commit cc4b9403b6
2 changed files with 22 additions and 1 deletions
@@ -39,11 +39,13 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.EditorPopupHandler;
import org.jetbrains.annotations.NotNull;
@@ -252,11 +254,20 @@ public class EditorActionUtil {
return isWordEnd(chars, offset, isCamel) || !isWordStart(chars, offset, isCamel) && isLexemeBoundary(editor, offset);
}
/**
* Finds out whether there's a boundary between two lexemes of different type at given offset.
*/
public static boolean isLexemeBoundary(@NotNull Editor editor, int offset) {
if (!(editor instanceof EditorEx) || offset <= 0 || offset >= editor.getDocument().getTextLength()) return false;
EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
HighlighterIterator it = highlighter.createIterator(offset);
return it.getStart() == offset;
if (it.getStart() != offset) {
return false;
}
IElementType rightToken = it.getTokenType();
it.retreat();
IElementType leftToken = it.getTokenType();
return !Comparing.equal(leftToken, rightToken);
}
public static boolean isWordStart(@NotNull CharSequence text, int offset, boolean isCamel) {
@@ -17,6 +17,8 @@ package com.intellij.openapi.editor.actions;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
@@ -94,4 +96,12 @@ public class NextPrevWordTest extends LightPlatformCodeInsightFixtureTestCase {
assertEquals(1, foldRegions.length);
assertFalse(foldRegions[0].isExpanded());
}
public void testRegexpCharsAreNotTreatedAsSeparateWords() {
FileType regExpFileType = FileTypeManagerEx.getInstanceEx().findFileTypeByName("RegExp");
assertNotNull(regExpFileType);
myFixture.configureByText(regExpFileType, "<caret>abc");
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD);
myFixture.checkResult("abc<caret>");
}
}