Skip to content

Commit 6b6dd81

Browse files
deepika-uelsazac
authored andcommitted
This commit enhances Quick Search dialog with
- Auto-show first result in preview. - Clear preview when search is empty removing stale entries.
1 parent 933b741 commit 6b6dd81

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

bundles/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchDialog.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.eclipse.jface.resource.JFaceResources;
5959
import org.eclipse.jface.text.BadLocationException;
6060
import org.eclipse.jface.text.CursorLinePainter;
61+
import org.eclipse.jface.text.Document;
6162
import org.eclipse.jface.text.IDocument;
6263
import org.eclipse.jface.text.IRegion;
6364
import org.eclipse.jface.text.source.CompositeRuler;
@@ -1173,6 +1174,9 @@ private void refreshDetails() {
11731174
viewer.revealRange(rangeStart, rangeEnd - rangeStart);
11741175

11751176
var targetLineFirstMatch = getQuery().findFirst(document.get(item.getOffset(), contextLenght - (item.getOffset() - start)));
1177+
if (targetLineFirstMatch == null) {
1178+
return; // nothing to refresh
1179+
}
11761180
int targetLineFirstMatchStart = item.getOffset() + targetLineFirstMatch.getOffset();
11771181
// sets caret position
11781182
viewer.setSelectedRange(targetLineFirstMatchStart, 0);
@@ -1289,6 +1293,10 @@ public void refreshWidgets() {
12891293
//element is available in the list.
12901294
openButton.setEnabled(itemCount>0);
12911295
}
1296+
//Auto-select the first search result for preview to be shown.
1297+
if (itemCount >= 1 && list.getSelection().isEmpty()) {
1298+
list.getTable().select(0);
1299+
}
12921300
refreshDetails();
12931301
}
12941302
}
@@ -1484,6 +1492,14 @@ public void update(LineItem match) {
14841492
} else {
14851493
//The QuickTextSearcher is already active update the query
14861494
this.searcher.setQuery(newFilter, force);
1495+
if(newFilter.getPatternString().trim().isEmpty()) {
1496+
//When pattern is cleared, clear the preview section
1497+
viewer.setDocument(new Document("")); //$NON-NLS-1$
1498+
if (lineNumberColumn != null) {
1499+
viewer.removeVerticalRulerColumn(lineNumberColumn);
1500+
viewer.addVerticalRulerColumn(lineNumberColumn);
1501+
}
1502+
}
14871503
}
14881504
if (progressJob!=null) {
14891505
progressJob.schedule();

0 commit comments

Comments
 (0)