Skip to content

Commit 4c3d962

Browse files
authored
Merge pull request #5383 from facchinm/solve_search_replace
Fix nextTab/prevTab selection logic
2 parents c1291ee + 1efa07f commit 4c3d962

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

app/src/cc/arduino/view/findreplace/FindReplace.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import processing.app.Base;
3333
import processing.app.Editor;
34+
import processing.app.EditorTab;
3435
import processing.app.helpers.OSUtils;
3536

3637
import 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

app/src/processing/app/EditorTab.java

-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ private SketchTextArea createTextArea(RSyntaxDocument document)
175175

176176
editor.lineStatus.set(lineStart, lineEnd);
177177
});
178-
179178
ToolTipManager.sharedInstance().registerComponent(textArea);
180179

181180
configurePopupMenu(textArea);

0 commit comments

Comments
 (0)