From c927237912ae5d43b63ea49672735613e6919fad Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 19 Sep 2016 11:20:19 +0200 Subject: [PATCH 1/5] Fix tab order in FindReplace When searching through all tabs, the order was accidentally reversed. This was broken by commit d2bac86 (Remove tab switching logic from Sketch). This also fixes a problem where "replace all" would only work on the first and last tab (since it would search backwards from the first tab to the last tab and then conclude it was done). This fixes a part of #5380. --- app/src/cc/arduino/view/findreplace/FindReplace.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/cc/arduino/view/findreplace/FindReplace.java b/app/src/cc/arduino/view/findreplace/FindReplace.java index f5e6a81f1..60dd6626a 100644 --- a/app/src/cc/arduino/view/findreplace/FindReplace.java +++ b/app/src/cc/arduino/view/findreplace/FindReplace.java @@ -345,12 +345,12 @@ public class FindReplace extends javax.swing.JFrame { } if (backwards) { - editor.selectNextTab(); + editor.selectPrevTab(); this.setVisible(true); int l = editor.getCurrentTab().getText().length() - 1; editor.getCurrentTab().setSelection(l, l); } else { - editor.selectPrevTab(); + editor.selectNextTab(); this.setVisible(true); editor.getCurrentTab().setSelection(0, 0); } From 97237263870be7651b6b0927731a4c8ee774d3e7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Sep 2016 13:45:11 +0200 Subject: [PATCH 2/5] Call ensureOffsetNotInClosedFold only when a match is found --- app/src/cc/arduino/view/findreplace/FindReplace.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/cc/arduino/view/findreplace/FindReplace.java b/app/src/cc/arduino/view/findreplace/FindReplace.java index 60dd6626a..5c53dee13 100644 --- a/app/src/cc/arduino/view/findreplace/FindReplace.java +++ b/app/src/cc/arduino/view/findreplace/FindReplace.java @@ -323,8 +323,6 @@ public class FindReplace extends javax.swing.JFrame { } } - editor.getCurrentTab().getTextArea().getFoldManager().ensureOffsetNotInClosedFold(nextIndex); - if (nextIndex == -1) { // Nothing found on this tab: Search other tabs if required if (searchTabs) { @@ -366,6 +364,7 @@ public class FindReplace extends javax.swing.JFrame { } if (nextIndex != -1) { + editor.getCurrentTab().getTextArea().getFoldManager().ensureOffsetNotInClosedFold(nextIndex); editor.getCurrentTab().setSelection(nextIndex, nextIndex + search.length()); return true; } From 47fcff77d553bb4eb212d4fa27b16e81f6b11bca Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Sep 2016 13:52:24 +0200 Subject: [PATCH 3/5] Simplify FindReplace.find() logic (part 1) The snippet: boolean wrapNeeded = false; if (wrap && nextIndex == -1) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } is present on both sides of the `if` statement so it can be factored out. --- .../cc/arduino/view/findreplace/FindReplace.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/cc/arduino/view/findreplace/FindReplace.java b/app/src/cc/arduino/view/findreplace/FindReplace.java index 5c53dee13..039834286 100644 --- a/app/src/cc/arduino/view/findreplace/FindReplace.java +++ b/app/src/cc/arduino/view/findreplace/FindReplace.java @@ -284,7 +284,6 @@ public class FindReplace extends javax.swing.JFrame { // End of variables declaration//GEN-END:variables private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int originTab) { - boolean wrapNeeded = false; String search = findField.getText(); if (search.length() == 0) { @@ -304,10 +303,6 @@ public class FindReplace extends javax.swing.JFrame { int selectionEnd = editor.getCurrentTab().getSelectionStop(); nextIndex = text.indexOf(search, selectionEnd); - if (wrap && nextIndex == -1) { - // if wrapping, a second chance is ok, start from beginning - wrapNeeded = true; - } } else { // int selectionStart = editor.textarea.getSelectionStart(); int selectionStart = editor.getCurrentTab().getSelectionStart() - 1; @@ -317,10 +312,12 @@ public class FindReplace extends javax.swing.JFrame { } else { nextIndex = -1; } - if (wrap && nextIndex == -1) { - // if wrapping, a second chance is ok, start from the end - wrapNeeded = true; - } + } + + boolean wrapNeeded = false; + if (wrap && nextIndex == -1) { + // if wrapping, a second chance is ok, start from the end + wrapNeeded = true; } if (nextIndex == -1) { From c5a6a44b55f43448f2a9d68ae296716da47aaf21 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Sep 2016 13:58:36 +0200 Subject: [PATCH 4/5] Simplify FindReplace.find() logic (part 2) The snippet: boolean wrapNeeded = false; if (wrap && nextIndex == -1) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } Can be moved inside the `if (nextIndex == -1)` that follows, this way: if (nextIndex == -1) { boolean wrapNeeded = false; if (wrap) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } [...CUT...] if (wrapNeeded) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } but since `wrapNeeded` is used only at the very end of the `if` statement we can move it forward: if (nextIndex == -1) { [...CUT...] boolean wrapNeeded = false; if (wrap) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } if (wrapNeeded) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } and finally simplify it by removing `wrapNeeded` altogether: if (nextIndex == -1) { [...CUT...] if (wrap) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } --- app/src/cc/arduino/view/findreplace/FindReplace.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/cc/arduino/view/findreplace/FindReplace.java b/app/src/cc/arduino/view/findreplace/FindReplace.java index 039834286..26282ceeb 100644 --- a/app/src/cc/arduino/view/findreplace/FindReplace.java +++ b/app/src/cc/arduino/view/findreplace/FindReplace.java @@ -314,12 +314,6 @@ public class FindReplace extends javax.swing.JFrame { } } - boolean wrapNeeded = false; - if (wrap && nextIndex == -1) { - // if wrapping, a second chance is ok, start from the end - wrapNeeded = true; - } - if (nextIndex == -1) { // Nothing found on this tab: Search other tabs if required if (searchTabs) { @@ -355,7 +349,7 @@ public class FindReplace extends javax.swing.JFrame { } } - if (wrapNeeded) { + if (wrap) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } From 1efa07f01058c249117d7f2b05984df86c156f2b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Sep 2016 15:31:17 +0200 Subject: [PATCH 5/5] Enable visibility of selection on find Fix #5380 --- app/src/cc/arduino/view/findreplace/FindReplace.java | 7 +++++-- app/src/processing/app/EditorTab.java | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/cc/arduino/view/findreplace/FindReplace.java b/app/src/cc/arduino/view/findreplace/FindReplace.java index 26282ceeb..6af1f397b 100644 --- a/app/src/cc/arduino/view/findreplace/FindReplace.java +++ b/app/src/cc/arduino/view/findreplace/FindReplace.java @@ -31,6 +31,7 @@ package cc.arduino.view.findreplace; import processing.app.Base; import processing.app.Editor; +import processing.app.EditorTab; import processing.app.helpers.OSUtils; import java.awt.*; @@ -355,8 +356,10 @@ public class FindReplace extends javax.swing.JFrame { } if (nextIndex != -1) { - editor.getCurrentTab().getTextArea().getFoldManager().ensureOffsetNotInClosedFold(nextIndex); - editor.getCurrentTab().setSelection(nextIndex, nextIndex + search.length()); + EditorTab currentTab = editor.getCurrentTab(); + currentTab.getTextArea().getFoldManager().ensureOffsetNotInClosedFold(nextIndex); + currentTab.setSelection(nextIndex, nextIndex + search.length()); + currentTab.getTextArea().getCaret().setSelectionVisible(true); return true; } diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java index 0a7278343..988b78136 100644 --- a/app/src/processing/app/EditorTab.java +++ b/app/src/processing/app/EditorTab.java @@ -175,7 +175,6 @@ public class EditorTab extends JPanel implements SketchFile.TextStorage { editor.lineStatus.set(lineStart, lineEnd); }); - ToolTipManager.sharedInstance().registerComponent(textArea); configurePopupMenu(textArea);