From 1a50247d62bef90cf9d2a88c2a7000f29b08f3d3 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 20 Feb 2014 15:56:12 +0100 Subject: [PATCH] IDEA-116706 Unselect word at caret doesn't work reversing through lambdarized anonymous class --- .../editorActions/UnSelectWordHandler.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/UnSelectWordHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/UnSelectWordHandler.java index ca3f22fff9bb..cb1d0a6f2be9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/UnSelectWordHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/UnSelectWordHandler.java @@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; @@ -54,7 +55,7 @@ public class UnSelectWordHandler extends EditorActionHandler { } - private static void doAction(Editor editor, PsiFile file) { + private static void doAction(final Editor editor, PsiFile file) { if (file instanceof PsiCompiledFile) { file = ((PsiCompiledFile)file).getDecompiledPsiFile(); if (file == null) return; @@ -108,7 +109,9 @@ public class UnSelectWordHandler extends EditorActionHandler { SelectWordUtil.processRanges(element, text, cursorOffset, editor, new Processor() { @Override public boolean process(TextRange range) { - if (selectionRange.contains(range) && !range.equals(selectionRange) && (range.contains(finalCursorOffset) || finalCursorOffset == range.getEndOffset())) { + if (selectionRange.contains(range) && !range.equals(selectionRange) && + (range.contains(finalCursorOffset) || finalCursorOffset == range.getEndOffset()) && + !isOffsetCollapsed(range.getStartOffset()) && !isOffsetCollapsed(range.getEndOffset())) { if (maximumRange.get() == null || range.contains(maximumRange.get())) { maximumRange.set(range); } @@ -116,6 +119,11 @@ public class UnSelectWordHandler extends EditorActionHandler { return false; } + + private boolean isOffsetCollapsed(int offset) { + FoldRegion region = editor.getFoldingModel().getCollapsedRegionAtOffset(offset); + return region != null && region.getStartOffset() != offset && region.getEndOffset() != offset; + } }); TextRange range = maximumRange.get();