mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
there are no \r's in documents & psi
This commit is contained in:
+12
-36
@@ -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<TextRange> ranges = expandToWholeLine(editorText, originalRange, true);
|
||||
|
||||
if (ranges.size() == 1 && ranges.contains(originalRange)) {
|
||||
ranges = expandToWholeLine(editorText, originalRange, false);
|
||||
return expandToWholeLine(editorText, originalRange, false);
|
||||
}
|
||||
|
||||
List<TextRange> result = ContainerUtil.newArrayList();
|
||||
result.addAll(ranges);
|
||||
return result;
|
||||
return ranges;
|
||||
}
|
||||
|
||||
public static List<TextRange> expandToWholeLine(CharSequence text, TextRange range, boolean isSymmetric) {
|
||||
public static List<TextRange> expandToWholeLine(CharSequence text, @Nullable TextRange range, boolean isSymmetric) {
|
||||
int textLength = text.length();
|
||||
List<TextRange> result = new ArrayList<TextRange>();
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user