1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01: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() {
if(findField.getText().length()==0)
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.getSketch().setModified(true); // TODO is this necessary?
}
if ( !foundAtLeastOne ) {
Toolkit.getDefaultToolkit().beep();
}
}
/**
* Replace the current selection with whatever's in the
* replacement text field, and then find the next match
@ -453,7 +468,8 @@ public class FindReplace extends JFrame implements ActionListener {
while ( true ) {
if ( find(false,false,searchAllFiles,-1)) {
foundAtLeastOne = true;
replace();
editor.setSelectedText(replaceField.getText());
editor.getSketch().setModified(true); // TODO is this necessary?
} else {
break;
}