Skip to content

Commit 48463b4

Browse files
committed
Show filter hint only as placeholder in filtered viewers
AbstractFilteredViewerComposite#setInitialText wrote the hint into the filter field value when the field had focus, which required clear-on-focus handling and could be misread by screen readers as an actual filter value. Expose the hint solely via Text#setMessage instead. This aligns FilteredTree, the e4 FilteredTree and FilteredTable with the approach already used by FilteredPreferenceDialog and ChooseWorkspaceDialog.
1 parent 968d4ce commit 48463b4

3 files changed

Lines changed: 9 additions & 27 deletions

File tree

bundles/org.eclipse.e4.ui.dialogs/src/org/eclipse/e4/ui/dialogs/filteredtree/FilteredTree.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,7 @@ protected Text doCreateFilterText(Composite parent) {
425425

426426
@Override
427427
protected void textChanged() {
428-
narrowingDown = previousFilterText == null
429-
|| previousFilterText.equals(E4DialogMessages.FilteredTree_FilterMessage)
430-
|| getFilterString().startsWith(previousFilterText);
428+
narrowingDown = previousFilterText == null || getFilterString().startsWith(previousFilterText);
431429
previousFilterText = getFilterString();
432430
// cancel currently running job first, to prevent unnecessary redraw
433431
refreshJob.cancel();

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractFilteredViewerComposite.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -279,30 +279,16 @@ protected String getFilterString() {
279279
}
280280

281281
/**
282-
* Set the text that will be shown until the first focus. A default value is
283-
* provided, so this method only need be called if overriding the default
284-
* initial text is desired.
282+
* Sets the placeholder hint shown while the filter field is empty.
285283
*
286-
* @param text initial text to appear in text field
284+
* @param text the placeholder hint for the filter field
287285
*/
288286
public void setInitialText(String text) {
289-
initialText = text;
290-
if (filterText != null) {
291-
filterText.setMessage(text);
292-
if (filterText.isFocusControl()) {
293-
setFilterText(initialText);
294-
textChanged();
295-
} else {
296-
getDisplay().asyncExec(() -> {
297-
if (!filterText.isDisposed() && filterText.isFocusControl()) {
298-
setFilterText(initialText);
299-
textChanged();
300-
}
301-
});
302-
}
303-
} else {
304-
setFilterText(initialText);
305-
textChanged();
287+
initialText = text != null ? text : ""; //$NON-NLS-1$
288+
if (filterText != null && !filterText.isDisposed()) {
289+
// Show the hint as placeholder only, never as field value (which would
290+
// need clear-on-focus handling and read as a value to screen readers).
291+
filterText.setMessage(initialText);
306292
}
307293
}
308294

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredTree.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,7 @@ protected Text doCreateFilterText(Composite parent) {
615615

616616
@Override
617617
protected void textChanged() {
618-
narrowingDown = previousFilterText == null
619-
|| previousFilterText.equals(WorkbenchMessages.FilteredTree_FilterMessage)
620-
|| getFilterString().startsWith(previousFilterText);
618+
narrowingDown = previousFilterText == null || getFilterString().startsWith(previousFilterText);
621619
previousFilterText = getFilterString();
622620
// cancel currently running job first, to prevent unnecessary redraw
623621
refreshJob.cancel();

0 commit comments

Comments
 (0)