Skip to content

Commit 9fbdf90

Browse files
committed
This commit enhances Quick Search dialog with
- Auto-show first result in preview. - Clear preview when search is empty removing stale entries. - Move Refresh button to the search pattern line towards the end.
1 parent 36f81f0 commit 9fbdf90

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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

Lines changed: 23 additions & 2 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;
@@ -688,7 +689,6 @@ private Label createLabels(Composite parent) {
688689
progressLabel = new Label(labels, SWT.RIGHT);
689690
gd = new GridData(GridData.FILL_HORIZONTAL);
690691
progressLabel.setLayoutData(gd);
691-
createButton(labels, REFRESH_BUTTON_ID, Messages.QuickSearchDialog_Refresh, false);
692692

693693
labels.setLayoutData(gd);
694694
return listLabel;
@@ -813,14 +813,20 @@ public void getName(AccessibleEvent e) {
813813
GridDataFactory.fillDefaults().span(6,1).grab(true, false).applyTo(pattern);
814814

815815
Composite searchInComposite = createNestedComposite(inputRow, 2, false);
816-
GridDataFactory.fillDefaults().span(4,1).grab(true, false).applyTo(searchInComposite);
816+
GridDataFactory.fillDefaults().span(3,1).grab(true, false).applyTo(searchInComposite);
817817
Label searchInLabel = new Label(searchInComposite, SWT.NONE);
818818
searchInLabel.setText(Messages.QuickSearchDialog_In);
819819
GridDataFactory.swtDefaults().indent(5, 0).applyTo(searchInLabel);
820820
searchIn = new Combo(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
821821
searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip);
822822
GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn);
823823

824+
// Refresh button next to pattern field towards extreme right
825+
Button refreshButton = new Button(inputRow, SWT.PUSH);
826+
refreshButton.setText(Messages.QuickSearchDialog_Refresh);
827+
GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(false, false).applyTo(refreshButton);
828+
refreshButton.addListener(SWT.Selection, e -> refreshButtonPressed());
829+
824830
listLabel = createLabels(content);
825831

826832
sashForm = new SashForm(content, SWT.VERTICAL);
@@ -1173,6 +1179,9 @@ private void refreshDetails() {
11731179
viewer.revealRange(rangeStart, rangeEnd - rangeStart);
11741180

11751181
var targetLineFirstMatch = getQuery().findFirst(document.get(item.getOffset(), contextLenght - (item.getOffset() - start)));
1182+
if (targetLineFirstMatch == null) {
1183+
return; // nothing to refresh
1184+
}
11761185
int targetLineFirstMatchStart = item.getOffset() + targetLineFirstMatch.getOffset();
11771186
// sets caret position
11781187
viewer.setSelectedRange(targetLineFirstMatchStart, 0);
@@ -1289,6 +1298,10 @@ public void refreshWidgets() {
12891298
//element is available in the list.
12901299
openButton.setEnabled(itemCount>0);
12911300
}
1301+
//Auto-select the first search result for preview to be shown.
1302+
if (itemCount >= 1 && list.getSelection().isEmpty()) {
1303+
list.getTable().select(0);
1304+
}
12921305
refreshDetails();
12931306
}
12941307
}
@@ -1484,6 +1497,14 @@ public void update(LineItem match) {
14841497
} else {
14851498
//The QuickTextSearcher is already active update the query
14861499
this.searcher.setQuery(newFilter, force);
1500+
if(newFilter.getPatternString().trim().isEmpty()) {
1501+
//When pattern is cleared, clear the preview section
1502+
viewer.setDocument(new Document("")); //$NON-NLS-1$
1503+
if (lineNumberColumn != null) {
1504+
viewer.removeVerticalRulerColumn(lineNumberColumn);
1505+
viewer.addVerticalRulerColumn(lineNumberColumn);
1506+
}
1507+
}
14871508
}
14881509
if (progressJob!=null) {
14891510
progressJob.schedule();

0 commit comments

Comments
 (0)