mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Theme Editor: use selected text in editor for searching when pressing Ctrl+F
This commit is contained in:
@@ -29,6 +29,7 @@ import org.fife.ui.rtextarea.SearchContext;
|
|||||||
import org.fife.ui.rtextarea.SearchEngine;
|
import org.fife.ui.rtextarea.SearchEngine;
|
||||||
import org.fife.ui.rtextarea.SearchResult;
|
import org.fife.ui.rtextarea.SearchResult;
|
||||||
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
||||||
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,6 +89,11 @@ class FlatFindReplaceBar
|
|||||||
public boolean requestFocusInWindow() {
|
public boolean requestFocusInWindow() {
|
||||||
// invoked from CollapsibleSectionPanel
|
// 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
|
// if showing bar, highlight matches in editor
|
||||||
// (not invoking this from addNotify() because this would break the slide-in animation)
|
// (not invoking this from addNotify() because this would break the slide-in animation)
|
||||||
markAll();
|
markAll();
|
||||||
@@ -136,7 +142,7 @@ class FlatFindReplaceBar
|
|||||||
updateMatchesLabel( result, false );
|
updateMatchesLabel( result, false );
|
||||||
|
|
||||||
// enabled/disable
|
// enabled/disable
|
||||||
boolean findEnabled = (searchFor != null && !searchFor.isEmpty());
|
boolean findEnabled = !StringUtils.isEmpty( searchFor );
|
||||||
findPreviousButton.setEnabled( findEnabled );
|
findPreviousButton.setEnabled( findEnabled );
|
||||||
findNextButton.setEnabled( findEnabled );
|
findNextButton.setEnabled( findEnabled );
|
||||||
}
|
}
|
||||||
@@ -158,6 +164,7 @@ class FlatFindReplaceBar
|
|||||||
|
|
||||||
private void replace() {
|
private void replace() {
|
||||||
// update search context
|
// update search context
|
||||||
|
context.setSearchFor( findField.getText() );
|
||||||
context.setReplaceWith( replaceField.getText() );
|
context.setReplaceWith( replaceField.getText() );
|
||||||
|
|
||||||
// replace
|
// replace
|
||||||
@@ -169,6 +176,7 @@ class FlatFindReplaceBar
|
|||||||
|
|
||||||
private void replaceAll() {
|
private void replaceAll() {
|
||||||
// update search context
|
// update search context
|
||||||
|
context.setSearchFor( findField.getText() );
|
||||||
context.setReplaceWith( replaceField.getText() );
|
context.setReplaceWith( replaceField.getText() );
|
||||||
|
|
||||||
// replace all
|
// replace all
|
||||||
|
|||||||
Reference in New Issue
Block a user