1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Fix search and replace #2106

This commit is contained in:
Fulvio Ieva
2014-07-24 10:52:56 +02:00
committed by Cristian Maglie
parent 6efbecd3cc
commit cd75cc24a2

View File

@ -426,10 +426,25 @@ public class FindReplace extends JFrame implements ActionListener {
public void replace() { public void replace() {
if(findField.getText().length()==0) if(findField.getText().length()==0)
return; return;
int newpos = editor.getSelectionStart() - findField.getText().length();
if (newpos < 0) newpos = 0;
editor.setSelection(newpos, newpos);
boolean foundAtLeastOne = false;
if ( find(false,false,searchAllFiles,-1)) {
foundAtLeastOne = true;
editor.setSelectedText(replaceField.getText()); editor.setSelectedText(replaceField.getText());
editor.getSketch().setModified(true); // TODO is this necessary? editor.getSketch().setModified(true); // TODO is this necessary?
} }
if ( !foundAtLeastOne ) {
Toolkit.getDefaultToolkit().beep();
}
}
/** /**
* Replace the current selection with whatever's in the * Replace the current selection with whatever's in the
* replacement text field, and then find the next match * replacement text field, and then find the next match
@ -453,7 +468,8 @@ public class FindReplace extends JFrame implements ActionListener {
while ( true ) { while ( true ) {
if ( find(false,false,searchAllFiles,-1)) { if ( find(false,false,searchAllFiles,-1)) {
foundAtLeastOne = true; foundAtLeastOne = true;
replace(); editor.setSelectedText(replaceField.getText());
editor.getSketch().setModified(true); // TODO is this necessary?
} else { } else {
break; break;
} }