Index: src/org/openide/explorer/view/TreeView.java =================================================================== RCS file: /cvs/openide/src/org/openide/explorer/view/TreeView.java,v retrieving revision 1.132 diff -u -r1.132 TreeView.java --- src/org/openide/explorer/view/TreeView.java 15 Apr 2003 15:10:37 -0000 1.132 +++ src/org/openide/explorer/view/TreeView.java 25 Apr 2003 13:59:16 -0000 @@ -1291,15 +1291,15 @@ private int currentSelectionIndex; public void changedUpdate(DocumentEvent e) { - searchForNode(); + searchForNode (true); } public void insertUpdate(DocumentEvent e) { - searchForNode(); + searchForNode (false); } public void removeUpdate(DocumentEvent e) { - searchForNode(); + searchForNode (true); } public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); @@ -1308,13 +1308,13 @@ ExplorerTree.this.requestFocus(); } else if (keyCode == KeyEvent.VK_UP) { currentSelectionIndex--; - displaySearchResult(); + displaySearchResult (true); // Stop processing the event here. Otherwise it's dispatched // to the tree too (which scrolls) e.consume(); } else if (keyCode == KeyEvent.VK_DOWN) { currentSelectionIndex++; - displaySearchResult(); + displaySearchResult (true); // Stop processing the event here. Otherwise it's dispatched // to the tree too (which scrolls) e.consume(); @@ -1331,20 +1331,26 @@ } /** Searches for a node in the tree. */ - private void searchForNode() { + private void searchForNode(boolean forceChangeSelection) { currentSelectionIndex = 0; results.clear(); maxPrefix = null; String text = searchTextField.getText().toUpperCase(); if (text.length() > 0) { - doSearch(text, results); - displaySearchResult(); + results = doSearch (text); + displaySearchResult (forceChangeSelection); } } - private void displaySearchResult() { + private void displaySearchResult (boolean forceChangeSelection) { int sz = results.size(); if (sz > 0) { + + if (!forceChangeSelection && results.contains (getSelectionPath ())) { + // current selection matches => no change + return ; + } + if (currentSelectionIndex < 0) { currentSelectionIndex = sz - 1; } else if (currentSelectionIndex >= sz) { @@ -1369,16 +1375,12 @@ private int originalScrollMode; - private void doSearch(String str, ArrayList results) { - int rows[] = getSelectionRows(); - int row = (rows == null || rows.length == 0) ? 0 : rows[0]; - int rowCount = getRowCount(); - for (int i = row; i < getRowCount(); i++) { - addPathIfMatches(str, i, results); - } - for (int i = 0; i < row && i < rowCount; i++) { - addPathIfMatches(str, i, results); + private ArrayList doSearch (String str) { + ArrayList results = new ArrayList (); + for (int i = 0; i < getRowCount (); i++) { + addPathIfMatches (str, i, results); } + return results; } private void addPathIfMatches(String str, int row, ArrayList results) {