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]