From a0efe207fc04b6561d9960eb8788b84149010d3a Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 24 Aug 2017 15:15:33 +0300 Subject: [PATCH] in some cases selection grows too fast --- .../ui/tree/TreeSmartSelectProvider.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/tree/TreeSmartSelectProvider.java b/platform/platform-impl/src/com/intellij/ui/tree/TreeSmartSelectProvider.java index 8ffe3311b256..cea05c390a36 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/TreeSmartSelectProvider.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/TreeSmartSelectProvider.java @@ -37,22 +37,38 @@ public class TreeSmartSelectProvider implements SmartSelectProvider { private static void increaseSelection(TreePath path, JTree tree) { TreePath parentPath = path.getParentPath(); - if (parentPath == null) return; + + if (parentPath == null) { + return; + } + boolean madeSelection = false; + for (int i = 0; i < tree.getRowCount(); i++) { TreePath row = tree.getPathForRow(i); if (parentPath.isDescendant(row) && !row.equals(parentPath)) { if (!tree.isRowSelected(i)) { madeSelection = true; - tree.getSelectionModel().addSelectionPath(row); + addSelection(tree, row); } } } + if (!madeSelection) { - increaseSelection(parentPath, tree); + if (tree.isRowSelected(tree.getRowForPath(parentPath))) { + increaseSelection(parentPath, tree); + } else { + addSelection(tree, parentPath); + } } } + private static void addSelection(JTree tree, TreePath path) { + TreePath leadPath = tree.getLeadSelectionPath(); + tree.getSelectionModel().addSelectionPath(path); + tree.setLeadSelectionPath(leadPath); + } + @Override public void decreaseSelection(JTree tree) { //todo[kb]