mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use the same algorithm to search for a tab for JTabbedPane, TabbedPaneWrapper
Don't use the first available tab if there are no words, search by title instead (e.g. "Other") GitOrigin-RevId: 38cab4d09ae404fe1a85b64afad1be60fd65456a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
32f357bc26
commit
8a886bfaee
@@ -27,6 +27,7 @@ import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -252,11 +253,11 @@ public class SearchUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getSelection(String tabIdx, final JTabbedPane tabbedPane) {
|
||||
private static int getSelection(String tabIdx, int tabCount, Function<Integer,String> titleGetter) {
|
||||
SearchableOptionsRegistrar searchableOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
|
||||
for (int i = 0; i < tabCount; i++) {
|
||||
final Set<String> pathWords = searchableOptionsRegistrar.getProcessedWords(tabIdx);
|
||||
final String title = tabbedPane.getTitleAt(i);
|
||||
final String title = titleGetter.apply(i);
|
||||
if (!pathWords.isEmpty()) {
|
||||
final Set<String> titleWords = searchableOptionsRegistrar.getProcessedWords(title);
|
||||
pathWords.removeAll(titleWords);
|
||||
@@ -271,19 +272,6 @@ public class SearchUtil {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getSelection(String tabIdx, final TabbedPaneWrapper tabbedPane) {
|
||||
SearchableOptionsRegistrar searchableOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
|
||||
final Set<String> pathWords = searchableOptionsRegistrar.getProcessedWords(tabIdx);
|
||||
final String title = tabbedPane.getTitleAt(i);
|
||||
final Set<String> titleWords = searchableOptionsRegistrar.getProcessedWords(title);
|
||||
pathWords.removeAll(titleWords);
|
||||
if (pathWords.isEmpty()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static boolean traverseComponentsTree(SearchableConfigurable configurable,
|
||||
JComponent rootComponent,
|
||||
@@ -312,7 +300,7 @@ public class SearchUtil {
|
||||
final JTabbedPane tabbedPane = (JTabbedPane)rootComponent;
|
||||
final String path = SearchableOptionsRegistrar.getInstance().getInnerPath(configurable, option);
|
||||
if (path != null) {
|
||||
final int index = getSelection(path, tabbedPane);
|
||||
final int index = getSelection(path, tabbedPane.getTabCount(), i -> tabbedPane.getTitleAt(i));
|
||||
if (index > -1 && index < tabbedPane.getTabCount()) {
|
||||
if (tabbedPane.getTabComponentAt(index) instanceof JComponent) {
|
||||
highlightComponent((JComponent)tabbedPane.getTabComponentAt(index), option);
|
||||
@@ -324,7 +312,7 @@ public class SearchUtil {
|
||||
final TabbedPaneWrapper tabbedPaneWrapper = ((TabbedPaneWrapper.TabbedPaneHolder)rootComponent).getTabbedPaneWrapper();
|
||||
final String path = SearchableOptionsRegistrar.getInstance().getInnerPath(configurable, option);
|
||||
if (path != null) {
|
||||
final int index = getSelection(path, tabbedPaneWrapper);
|
||||
final int index = getSelection(path, tabbedPaneWrapper.getTabCount(), i -> tabbedPaneWrapper.getTitleAt(i));;
|
||||
if (index > -1 && index < tabbedPaneWrapper.getTabCount()) {
|
||||
highlightComponent((JComponent)tabbedPaneWrapper.getTabComponentAt(index), option);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user