Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve search bar behavior when using key bindings #2074

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/codearea/CodePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CodePanel(AbstractCodeArea codeArea) {

@Override
public void actionPerformed(ActionEvent e) {
searchBar.toggle();
searchBar.showAndFocus();
}
});
JMenuItem searchItem = new JMenuItem();
Expand Down
20 changes: 19 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/codearea/SearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ public void keyReleased(KeyEvent e) {
setVisible(false);
}

/*
* Replicates IntelliJ's search bar behavior
* 1.1. If the user has selected text, use that as the search text
* 1.2. Otherwise, use the previous search text (or empty if none)
* 2. Select all text in the search bar and give it focus
*/
public void showAndFocus() {
setVisible(true);

String selectedText = rTextArea.getSelectedText();
if (!StringUtils.isEmpty(selectedText)) {
searchField.setText(selectedText);
}

searchField.selectAll();
searchField.requestFocus();
}

public void toggle() {
boolean visible = !isVisible();
setVisible(visible);
Expand All @@ -149,8 +167,8 @@ public void toggle() {
if (!StringUtils.isEmpty(preferText)) {
searchField.setText(preferText);
}
searchField.requestFocus();
searchField.selectAll();
searchField.requestFocus();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was changed so that we don't request focus before having all the text selected (for fast keyboard users :P)

} else {
rTextArea.requestFocus();
}
Expand Down