Repository: spyder-ide/spyder

Issue:
Find does not open code-folded blocks
This one is probably trickier.
if the target is inside a folded bloc, then searching for it does not make anything. Same with successive search.
The difficulty would be to open a folded bloc, and close it back automatically on successive F3 (expected behavior).


Discussion:
Are you taking about code folding?
> Are you taking about code folding?

Yes, this is related to code folding

Steps to reproduce:
- Fold some code
- Search something that exist in that folded section
- The search partially works, if you unfold the section it the text is selected, but you don't see it because the block is folded.

> The difficulty would be to open a folded bloc, and close it back automatically on successive F3 (expected behavior).

I think the expected behavior is to unfold the block when searching, but not close it back.
>I think the expected behavior is to unfold the block when searching, but not close it back.

I agree with this!
Actually if one make successive find (eg pressing F3) and that find steps enter a folded block, the block should obviously be opened. But if F3 is pressed one more (because this find is of no interest) then upon leaving the block, it should be folded back (because one will have to close it back manually). I was thinking of this scenario in my earlier description. 

In the meantime I've checked Visual Studio, it does not fold a block back in this scenario. IMHO it is not the best, but already better then actual situation. Thanks.

Resolving patch:
diff --git a/spyder/utils/editor.py b/spyder/utils/editor.py
--- a/spyder/utils/editor.py
+++ b/spyder/utils/editor.py
@@ -134,20 +134,26 @@ def goto_line(self, line, column=0, move=True):
                                      column)
         if move:
             block = text_cursor.block()
-            # unfold parent fold trigger if the block is collapsed
-            try:
-                folding_panel = self._editor.panels.get('FoldingPanel')
-            except KeyError:
-                pass
-            else:
-                from spyder.widgets.sourcecode.folding import FoldScope
-                if not block.isVisible():
-                    block = FoldScope.find_parent_scope(block)
-                    if TextBlockHelper.is_collapsed(block):
-                        folding_panel.toggle_fold_trigger(block)
+            self.unfold_if_colapsed(block)
             self._editor.setTextCursor(text_cursor)
         return text_cursor
 
+    def unfold_if_colapsed(self, block):
+        """Unfold parent fold trigger if the block is collapsed.
+
+        :param block: Block to unfold.
+        """
+        try:
+            folding_panel = self._editor.panels.get('FoldingPanel')
+        except KeyError:
+            pass
+        else:
+            from spyder.widgets.sourcecode.folding import FoldScope
+            if not block.isVisible():
+                block = FoldScope.find_parent_scope(block)
+                if TextBlockHelper.is_collapsed(block):
+                    folding_panel.toggle_fold_trigger(block)
+
     def selected_text(self):
         """Returns the selected text."""
         return self._editor.textCursor().selectedText()
diff --git a/spyder/widgets/findreplace.py b/spyder/widgets/findreplace.py
--- a/spyder/widgets/findreplace.py
+++ b/spyder/widgets/findreplace.py
@@ -25,6 +25,7 @@
 from spyder.config.gui import config_shortcut
 from spyder.py3compat import to_text_string
 from spyder.utils import icon_manager as ima
+from spyder.utils.editor import TextHelper
 from spyder.utils.qthelpers import create_toolbutton, get_icon
 from spyder.widgets.comboboxes import PatternComboBox
 
@@ -391,6 +392,9 @@ def find(self, changed=True, forward=True,
                                           words=words, regexp=regexp)
             self.search_text.lineEdit().setStyleSheet(self.STYLE[found])
             if self.is_code_editor and found:
+                block = self.editor.textCursor().block()
+                TextHelper(self.editor).unfold_if_colapsed(block)
+
                 if rehighlight or not self.editor.found_results:
                     self.highlight_timer.stop()
                     if start_highlight_timer:


Test patch: