From 56ecd09734a732e6773c19505e4d3863074afe61 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 24 Sep 2012 15:08:02 +0400 Subject: [PATCH] there are no \r's in documents & psi --- .../ExtendWordSelectionHandlerBase.java | 48 +++++-------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java index 2a3ab0977eb7..8e899b89aa5a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/ExtendWordSelectionHandlerBase.java @@ -19,9 +19,10 @@ package com.intellij.codeInsight.editorActions; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CharArrayUtil; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -43,15 +44,13 @@ public abstract class ExtendWordSelectionHandlerBase implements ExtendWordSelect List ranges = expandToWholeLine(editorText, originalRange, true); if (ranges.size() == 1 && ranges.contains(originalRange)) { - ranges = expandToWholeLine(editorText, originalRange, false); + return expandToWholeLine(editorText, originalRange, false); } - List result = ContainerUtil.newArrayList(); - result.addAll(ranges); - return result; + return ranges; } - public static List expandToWholeLine(CharSequence text, TextRange range, boolean isSymmetric) { + public static List expandToWholeLine(CharSequence text, @Nullable TextRange range, boolean isSymmetric) { int textLength = text.length(); List result = new ArrayList(); @@ -60,18 +59,7 @@ public abstract class ExtendWordSelectionHandlerBase implements ExtendWordSelect } LOG.assertTrue(range.getEndOffset() <= text.length()); - boolean hasNewLines = false; - - for (int i = range.getStartOffset(); i < range.getEndOffset(); i++) { - char c = text.charAt(i); - - if (c == '\r' || c == '\n') { - hasNewLines = true; - break; - } - } - - if (!hasNewLines) { + if (!StringUtil.contains(text, range.getStartOffset(), range.getEndOffset(), '\n')) { result.add(range); } @@ -79,45 +67,33 @@ public abstract class ExtendWordSelectionHandlerBase implements ExtendWordSelect int startOffset = range.getStartOffset(); int endOffset = range.getEndOffset(); int index1 = CharArrayUtil.shiftBackward(text, startOffset - 1, " \t"); - if (endOffset > startOffset && text.charAt(endOffset - 1) == '\n' || text.charAt(endOffset - 1) == '\r') { + if (endOffset > startOffset && text.charAt(endOffset - 1) == '\n') { endOffset--; } int index2 = Math.min(textLength, CharArrayUtil.shiftForward(text, endOffset, " \t")); - if (index1 < 0 - || text.charAt(index1) == '\n' - || text.charAt(index1) == '\r' - || index2 == textLength - || text.charAt(index2) == '\n' - || text.charAt(index2) == '\r') { - + if (index1 < 0 || text.charAt(index1) == '\n' || index2 == textLength || text.charAt(index2) == '\n') { if (!isSymmetric) { - if (index1 < 0 || text.charAt(index1) == '\n' || text.charAt(index1) == '\r') { + if (index1 < 0 || text.charAt(index1) == '\n') { startOffset = index1 + 1; } - if (index2 == textLength || text.charAt(index2) == '\n' || text.charAt(index2) == '\r') { + if (index2 == textLength || text.charAt(index2) == '\n') { endOffset = index2; if (endOffset < textLength) { endOffset++; - if (endOffset < textLength && text.charAt(endOffset - 1) == '\r' && text.charAt(endOffset) == '\n') { - endOffset++; - } } } result.add(new TextRange(startOffset, endOffset)); } else { - if ((index1 < 0 || text.charAt(index1) == '\n' || text.charAt(index1) == '\r') && - (index2 == textLength || text.charAt(index2) == '\n' || text.charAt(index2) == '\r')) { + if ((index1 < 0 || text.charAt(index1) == '\n') && + (index2 == textLength || text.charAt(index2) == '\n')) { startOffset = index1 + 1; endOffset = index2; if (endOffset < textLength) { endOffset++; - if (endOffset < textLength && text.charAt(endOffset - 1) == '\r' && text.charAt(endOffset) == '\n') { - endOffset++; - } } result.add(new TextRange(startOffset, endOffset)); }