void (@NotNull AnActionEvent e) { TreeSelectionModel sm = myTree.getSelectionModel(); String query = mySearch.getEnteredPrefix(); if (query == null) return; List<TreePath> filtered = mySearch.findAllFilteredElements(query); if (filtered.isEmpty()) return; boolean alreadySelected = sm.getSelectionCount() == filtered.size() && ContainerUtil.and(filtered, (path) -> sm.isPathSelected(path)); if (alreadySelected) { TreePath anchor = myTree.getAnchorSelectionPath(); sm.setSelectionPath(anchor); myTree.setAnchorSelectionPath(anchor); mySearch.findAndSelectElement(query); } else { TreePath currentElement = (TreePath)mySearch.findElement(query); TreePath anchor = ObjectUtils.chooseNotNull(currentElement, filtered.get(0)); sm.setSelectionPaths(toTreePathArray(filtered)); myTree.setAnchorSelectionPath(anchor); } }