Theme Editor: use selected text in editor for searching when pressing Ctrl+F

This commit is contained in:
Karl Tauber
2021-01-01 12:56:29 +01:00
parent 89d0c301c2
commit 15ba00a902

View File

@@ -29,6 +29,7 @@ import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
import org.fife.ui.rtextarea.SearchResult;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.formdev.flatlaf.util.StringUtils;
import net.miginfocom.swing.*;
/**
@@ -88,6 +89,11 @@ class FlatFindReplaceBar
public boolean requestFocusInWindow() {
// invoked from CollapsibleSectionPanel
// use selected text in editor for searching
String selectedText = textArea.getSelectedText();
if( !StringUtils.isEmpty( selectedText ) && selectedText.indexOf( '\n' ) < 0 )
findField.setText( selectedText );
// if showing bar, highlight matches in editor
// (not invoking this from addNotify() because this would break the slide-in animation)
markAll();
@@ -136,7 +142,7 @@ class FlatFindReplaceBar
updateMatchesLabel( result, false );
// enabled/disable
boolean findEnabled = (searchFor != null && !searchFor.isEmpty());
boolean findEnabled = !StringUtils.isEmpty( searchFor );
findPreviousButton.setEnabled( findEnabled );
findNextButton.setEnabled( findEnabled );
}
@@ -158,6 +164,7 @@ class FlatFindReplaceBar
private void replace() {
// update search context
context.setSearchFor( findField.getText() );
context.setReplaceWith( replaceField.getText() );
// replace
@@ -169,6 +176,7 @@ class FlatFindReplaceBar
private void replaceAll() {
// update search context
context.setSearchFor( findField.getText() );
context.setReplaceWith( replaceField.getText() );
// replace all