mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move caret to next/prev word to treat $ as hump separator
This commit is contained in:
@@ -19,6 +19,7 @@ package com.intellij.codeInsight.editorActions;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.FileASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actions.EditorActionUtil;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
@@ -89,11 +90,11 @@ public class SelectWordUtil {
|
||||
int end = cursorOffset + 1;
|
||||
final int textLen = editorText.length();
|
||||
|
||||
while (start > 0 && Character.isJavaIdentifierPart(editorText.charAt(start - 1)) && !isWordBound(editorText, start)) {
|
||||
while (start > 0 && Character.isJavaIdentifierPart(editorText.charAt(start - 1)) && !EditorActionUtil.isHumpBound(editorText, start, true)) {
|
||||
start--;
|
||||
}
|
||||
|
||||
while (end < textLen && Character.isJavaIdentifierPart(editorText.charAt(end)) && !isWordBound(editorText, end)) {
|
||||
while (end < textLen && Character.isJavaIdentifierPart(editorText.charAt(end)) && !EditorActionUtil.isHumpBound(editorText, end, false)) {
|
||||
end++;
|
||||
}
|
||||
|
||||
@@ -105,19 +106,6 @@ public class SelectWordUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isWordBound(CharSequence editorText, int offset) {
|
||||
final char prevChar = editorText.charAt(offset - 1);
|
||||
final char curChar = editorText.charAt(offset);
|
||||
final char nextChar = offset + 1 < editorText.length() ? editorText.charAt(offset + 1) : 0; // 0x00 is not lowercase.
|
||||
|
||||
return Character.isLowerCase(prevChar) && Character.isUpperCase(curChar) ||
|
||||
prevChar == '_' && curChar != '_' ||
|
||||
prevChar != '_' && curChar == '_' ||
|
||||
prevChar == '$' && Character.isLetterOrDigit(curChar) ||
|
||||
Character.isLetterOrDigit(prevChar) && curChar == '$' ||
|
||||
Character.isUpperCase(prevChar) && Character.isUpperCase(curChar) && Character.isLowerCase(nextChar);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextRange getWordSelectionRange(@NotNull CharSequence editorText, int cursorOffset) {
|
||||
int length = editorText.length();
|
||||
|
||||
+15
-8
@@ -184,7 +184,6 @@ public class EditorActionUtil {
|
||||
public static boolean isWordStart(CharSequence text, int offset, boolean isCamel) {
|
||||
char prev = offset > 0 ? text.charAt(offset - 1) : 0;
|
||||
char current = text.charAt(offset);
|
||||
char next = offset + 1 < text.length() ? text.charAt(offset + 1) : 0;
|
||||
|
||||
final boolean firstIsIdentifierPart = Character.isJavaIdentifierPart(prev);
|
||||
final boolean secondIsIdentifierPart = Character.isJavaIdentifierPart(current);
|
||||
@@ -192,13 +191,8 @@ public class EditorActionUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isCamel) {
|
||||
if (firstIsIdentifierPart && secondIsIdentifierPart &&
|
||||
(isLowerCaseOrDigit(prev) && Character.isUpperCase(current) ||
|
||||
prev == '_' && current != '_' ||
|
||||
Character.isUpperCase(prev) && Character.isUpperCase(current) && isLowerCaseOrDigit(next))) {
|
||||
return true;
|
||||
}
|
||||
if (isCamel && firstIsIdentifierPart && secondIsIdentifierPart && isHumpBound(text, offset, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (Character.isWhitespace(prev) || firstIsIdentifierPart) &&
|
||||
@@ -729,4 +723,17 @@ public class EditorActionUtil {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isHumpBound(CharSequence editorText, int offset, boolean start) {
|
||||
final char prevChar = editorText.charAt(offset - 1);
|
||||
final char curChar = editorText.charAt(offset);
|
||||
final char nextChar = offset + 1 < editorText.length() ? editorText.charAt(offset + 1) : 0; // 0x00 is not lowercase.
|
||||
|
||||
return isLowerCaseOrDigit(prevChar) && Character.isUpperCase(curChar) ||
|
||||
start && prevChar == '_' && curChar != '_' ||
|
||||
!start && prevChar != '_' && curChar == '_' ||
|
||||
start && prevChar == '$' && Character.isLetterOrDigit(curChar) ||
|
||||
!start && Character.isLetterOrDigit(prevChar) && curChar == '$' ||
|
||||
Character.isUpperCase(prevChar) && Character.isUpperCase(curChar) && Character.isLowerCase(nextChar);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user