From 4196832b4b2c994f50ff83c500b2c1958b8ea3f3 Mon Sep 17 00:00:00 2001 From: Filipp Vakhitov Date: Mon, 6 Feb 2023 20:31:20 +0200 Subject: [PATCH] IDEA-110607 Double clicking space/tab characters should select all space/tab characters until it encounters another type of character Much better Expand Selection behavior when some whitespaces are already selected GitOrigin-RevId: f5042c1c1487a41d701e30026a7b33f5ae1e8450 --- .../codeInsight/editorActions/SelectWordHandler.java | 2 +- .../codeInsight/editorActions/SelectWordUtil.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java index 978edc684779..64bcdbd364c3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordHandler.java @@ -127,7 +127,7 @@ public class SelectWordHandler extends EditorActionHandler.ForEachCaret { } } - if (!(element instanceof PsiWhiteSpace && SelectWordUtil.canWhiteSpaceBeExpanded((PsiWhiteSpace) element, caretOffset))) { + if (!(element instanceof PsiWhiteSpace && SelectWordUtil.canWhiteSpaceBeExpanded((PsiWhiteSpace) element, caretOffset, caret))) { while (element instanceof PsiWhiteSpace || element != null && StringUtil.isEmptyOrSpaces(element.getText())) { while (element.getNextSibling() == null) { if (element instanceof PsiFile) return null; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java index 7df72b0b32c9..b5d9dbd64e25 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java @@ -5,6 +5,7 @@ package com.intellij.codeInsight.editorActions; import com.intellij.lang.ASTNode; import com.intellij.lang.FileASTNode; import com.intellij.lexer.Lexer; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actions.EditorActionUtil; import com.intellij.openapi.project.DumbService; @@ -269,11 +270,13 @@ public final class SelectWordUtil { * Returns if there is any expandable whitespace belonging to the given psiWhiteSpace * by any side of a caret at specified cursorPosition */ - public static boolean canWhiteSpaceBeExpanded(PsiWhiteSpace psiWhiteSpace, int cursorPosition) { - Character charBeforeCursor = getCharBeforeCursorInPsiElement(psiWhiteSpace, cursorPosition); + public static boolean canWhiteSpaceBeExpanded(PsiWhiteSpace psiWhiteSpace, int cursorPosition, Caret caret) { + int beforeOffset = caret.hasSelection()? caret.getSelectionStart() : cursorPosition; + Character charBeforeCursor = getCharBeforeCursorInPsiElement(psiWhiteSpace, beforeOffset); if (charBeforeCursor != null && isExpandableWhiteSpace(charBeforeCursor)) return true; - Character charAfterCursor = getCharAfterCursorInPsiElement(psiWhiteSpace, cursorPosition); + int afterOffset = caret.hasSelection()? caret.getSelectionEnd() : cursorPosition; + Character charAfterCursor = getCharAfterCursorInPsiElement(psiWhiteSpace, afterOffset); if (charAfterCursor != null && isExpandableWhiteSpace(charAfterCursor)) return true; return false;