3131
3232import processing .app .Base ;
3333import processing .app .Editor ;
34+ import processing .app .EditorTab ;
3435import processing .app .helpers .OSUtils ;
3536
3637import java .awt .*;
@@ -284,7 +285,6 @@ private void replaceAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//
284285 // End of variables declaration//GEN-END:variables
285286
286287 private boolean find (boolean wrap , boolean backwards , boolean searchTabs , int originTab ) {
287- boolean wrapNeeded = false ;
288288 String search = findField .getText ();
289289
290290 if (search .length () == 0 ) {
@@ -304,10 +304,6 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
304304 int selectionEnd = editor .getCurrentTab ().getSelectionStop ();
305305
306306 nextIndex = text .indexOf (search , selectionEnd );
307- if (wrap && nextIndex == -1 ) {
308- // if wrapping, a second chance is ok, start from beginning
309- wrapNeeded = true ;
310- }
311307 } else {
312308 // int selectionStart = editor.textarea.getSelectionStart();
313309 int selectionStart = editor .getCurrentTab ().getSelectionStart () - 1 ;
@@ -317,14 +313,8 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
317313 } else {
318314 nextIndex = -1 ;
319315 }
320- if (wrap && nextIndex == -1 ) {
321- // if wrapping, a second chance is ok, start from the end
322- wrapNeeded = true ;
323- }
324316 }
325317
326- editor .getCurrentTab ().getTextArea ().getFoldManager ().ensureOffsetNotInClosedFold (nextIndex );
327-
328318 if (nextIndex == -1 ) {
329319 // Nothing found on this tab: Search other tabs if required
330320 if (searchTabs ) {
@@ -345,12 +335,12 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
345335 }
346336
347337 if (backwards ) {
348- editor .selectNextTab ();
338+ editor .selectPrevTab ();
349339 this .setVisible (true );
350340 int l = editor .getCurrentTab ().getText ().length () - 1 ;
351341 editor .getCurrentTab ().setSelection (l , l );
352342 } else {
353- editor .selectPrevTab ();
343+ editor .selectNextTab ();
354344 this .setVisible (true );
355345 editor .getCurrentTab ().setSelection (0 , 0 );
356346 }
@@ -360,13 +350,16 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
360350 }
361351 }
362352
363- if (wrapNeeded ) {
353+ if (wrap ) {
364354 nextIndex = backwards ? text .lastIndexOf (search ) : text .indexOf (search , 0 );
365355 }
366356 }
367357
368358 if (nextIndex != -1 ) {
369- editor .getCurrentTab ().setSelection (nextIndex , nextIndex + search .length ());
359+ EditorTab currentTab = editor .getCurrentTab ();
360+ currentTab .getTextArea ().getFoldManager ().ensureOffsetNotInClosedFold (nextIndex );
361+ currentTab .setSelection (nextIndex , nextIndex + search .length ());
362+ currentTab .getTextArea ().getCaret ().setSelectionVisible (true );
370363 return true ;
371364 }
372365
0 commit comments