From 67c9589409f9d255d5338043a24d900fd672cb86 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Sat, 5 Mar 2005 21:11:00 +0300 Subject: [PATCH] IDEADEV-409: Camel words selection and navigation enhancement. GUIDGenerator breaks into 2 words: [GUID][Generator]. --- .../editorActions/SelectWordUtil.java | 6 +++-- .../editor/actions/DeleteToWordEndAction.java | 4 ++-- .../editor/actions/EditorActionUtil.java | 22 +++++++++++++------ .../editor/impl/SelectionModelImpl.java | 4 ++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/source/com/intellij/codeInsight/editorActions/SelectWordUtil.java b/source/com/intellij/codeInsight/editorActions/SelectWordUtil.java index 4334b76430b1..69aa1a232193 100644 --- a/source/com/intellij/codeInsight/editorActions/SelectWordUtil.java +++ b/source/com/intellij/codeInsight/editorActions/SelectWordUtil.java @@ -271,7 +271,8 @@ public class SelectWordUtil { final char prevChar = editorText.charAt(start - 1); final char curChar = editorText.charAt(start); - if (Character.isLowerCase(prevChar) && Character.isUpperCase(curChar) || prevChar == '_' && curChar != '_') { + if (Character.isLowerCase(prevChar) && Character.isUpperCase(curChar) || prevChar == '_' && curChar != '_' || + Character.isUpperCase(prevChar) && Character.isUpperCase(curChar) && Character.isLowerCase(editorText.charAt(start + 1))) { break; } start--; @@ -280,7 +281,8 @@ public class SelectWordUtil { while (end < editorText.length() && Character.isJavaIdentifierPart(editorText.charAt(end))) { final char prevChar = editorText.charAt(end - 1); final char curChar = editorText.charAt(end); - if (Character.isLowerCase(prevChar) && Character.isUpperCase(curChar) || prevChar != '_' && curChar == '_') { + if (Character.isLowerCase(prevChar) && Character.isUpperCase(curChar) || prevChar != '_' && curChar == '_' || + Character.isUpperCase(prevChar) && Character.isUpperCase(curChar) && Character.isLowerCase(editorText.charAt(end + 1))) { break; } end++; diff --git a/source/com/intellij/openapi/editor/actions/DeleteToWordEndAction.java b/source/com/intellij/openapi/editor/actions/DeleteToWordEndAction.java index 23dc767a8bd5..7a1ec2de9483 100644 --- a/source/com/intellij/openapi/editor/actions/DeleteToWordEndAction.java +++ b/source/com/intellij/openapi/editor/actions/DeleteToWordEndAction.java @@ -51,8 +51,8 @@ public class DeleteToWordEndAction extends EditorAction { } boolean camel = editor.getSettings().isCamelWords(); for (; newOffset < maxOffset; newOffset++) { - if (EditorActionUtil.isWordEnd(text.charAt(newOffset - 1), text.charAt(newOffset), camel) || - EditorActionUtil.isWordStart(text.charAt(newOffset - 1), text.charAt(newOffset), camel)) { + if (EditorActionUtil.isWordEnd(text, newOffset, camel) || + EditorActionUtil.isWordStart(text, newOffset, camel)) { break; } } diff --git a/source/com/intellij/openapi/editor/actions/EditorActionUtil.java b/source/com/intellij/openapi/editor/actions/EditorActionUtil.java index 1c0ed46fcb57..6b5c08e8a777 100644 --- a/source/com/intellij/openapi/editor/actions/EditorActionUtil.java +++ b/source/com/intellij/openapi/editor/actions/EditorActionUtil.java @@ -121,16 +121,20 @@ public class EditorActionUtil { editor.getCaretModel().moveToOffset(newCaretOffset); } - public static boolean isWordStart(char first, char second, boolean isCamel) { + public static boolean isWordStart(CharSequence text, int offset, boolean isCamel) { + char first = text.charAt(offset - 1); + char second = text.charAt(offset); final boolean firstIsIdentifierPart = Character.isJavaIdentifierPart(first); final boolean secondIsIdentifierPart = Character.isJavaIdentifierPart(second); if (!firstIsIdentifierPart && secondIsIdentifierPart) { return true; } - + if (isCamel) { if (firstIsIdentifierPart && secondIsIdentifierPart && - (Character.isLowerCase(first) && Character.isUpperCase(second) || first == '_' && second != '_')) { + (Character.isLowerCase(first) && Character.isUpperCase(second) || + first == '_' && second != '_' || + offset + 1 < text.length() && Character.isUpperCase(first) && Character.isUpperCase(second)) && Character.isLowerCase(text.charAt(offset + 1))) { return true; } } @@ -139,7 +143,9 @@ public class EditorActionUtil { !Character.isWhitespace(second) && !secondIsIdentifierPart; } - public static boolean isWordEnd(char first, char second, boolean isCamel) { + public static boolean isWordEnd(CharSequence text, int offset, boolean isCamel) { + char first = text.charAt(offset - 1); + char second = text.charAt(offset); final boolean firstIsIdentifiePart = Character.isJavaIdentifierPart(first); final boolean secondIsIdentifierPart = Character.isJavaIdentifierPart(second); if (firstIsIdentifiePart && !secondIsIdentifierPart) { @@ -148,7 +154,9 @@ public class EditorActionUtil { if (isCamel) { if (firstIsIdentifiePart && secondIsIdentifierPart && - (Character.isLowerCase(first) && Character.isUpperCase(second) || first != '_' && second == '_')) { + (Character.isLowerCase(first) && Character.isUpperCase(second) || first != '_' && second == '_' || + offset + 1 < text.length() && Character.isUpperCase(first) && + Character.isUpperCase(second)) && Character.isLowerCase(text.charAt(offset + 1))) { return true; } } @@ -328,7 +336,7 @@ public class EditorActionUtil { } boolean camel = editor.getSettings().isCamelWords(); for (; newOffset < maxOffset; newOffset++) { - if (isWordStart(text.charAt(newOffset - 1), text.charAt(newOffset), camel)) { + if (isWordStart(text, newOffset, camel)) { break; } } @@ -372,7 +380,7 @@ public class EditorActionUtil { int minOffset = lineNumber > 0 ? document.getLineEndOffset(lineNumber - 1) : 0; boolean camel = editor.getSettings().isCamelWords(); for (; newOffset > minOffset; newOffset--) { - if (isWordStart(text.charAt(newOffset - 1), text.charAt(newOffset), camel)) break; + if (isWordStart(text, newOffset, camel)) break; } editor.getCaretModel().moveToOffset(newOffset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); diff --git a/source/com/intellij/openapi/editor/impl/SelectionModelImpl.java b/source/com/intellij/openapi/editor/impl/SelectionModelImpl.java index 353722713e20..aaeb184ea818 100644 --- a/source/com/intellij/openapi/editor/impl/SelectionModelImpl.java +++ b/source/com/intellij/openapi/editor/impl/SelectionModelImpl.java @@ -451,7 +451,7 @@ public class SelectionModelImpl implements SelectionModel, DocumentListener { int minOffset = lineNumber > 0 ? document.getLineEndOffset(lineNumber - 1) : 0; boolean camel = myEditor.getSettings().isCamelWords(); for (; newOffset > minOffset; newOffset--) { - if (EditorActionUtil.isWordStart(text.charAt(newOffset - 1), text.charAt(newOffset), camel)) break; + if (EditorActionUtil.isWordStart(text, newOffset, camel)) break; } return newOffset; @@ -474,7 +474,7 @@ public class SelectionModelImpl implements SelectionModel, DocumentListener { } boolean camel = myEditor.getSettings().isCamelWords(); for (; newOffset < maxOffset; newOffset++) { - if (EditorActionUtil.isWordEnd(text.charAt(newOffset - 1), text.charAt(newOffset), camel)) break; + if (EditorActionUtil.isWordEnd(text, newOffset, camel)) break; } return newOffset;