Repository: spyder-ide/spyder

Issue:
Not able to create a new breakpoint after a collapsed function
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

## Problem Description
If a function is collapsed, a new breakpoint cannot be created in the lines below it. 

### What steps reproduce the problem?

1. Create a function and collapse it
2. Try to create a new breakpoint in any of the lines below
3. Nothing happens

### What is the expected output? What do you see instead?

We should be able to modify the state of breakpoints after a collapsed function.

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: Spyder 4.0.0.dev0 (Commit: 886f73cff)
* Python version: 3.6.8
* Qt version: 5.12.2
* PyQt version: 5.12.1
* Operating System name/version: Darwin 18.2.0 




Discussion:
@dalthviz, given that you work on the debugger panel, you have any ideas about where @steff456 can start looking to solve this bug?
@ccordoba12 @steff456 after testing a little bit it seems like when collapsing the code the debug panel is not mapping correctly the space released for the collapsed lines so for example:

![debug](https://user-images.githubusercontent.com/16781833/58604984-4fe10c00-8264-11e9-8c57-38a082009c36.gif)



Also it seems that even if not showing when the code is collapsed, the breakpoint its being set:

![debug2](https://user-images.githubusercontent.com/16781833/58605235-10ff8600-8265-11e9-995c-906a0d258e39.gif)

So we need to make the debug panel to follow the mapping created by the folding panel?
Yep :)

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py
--- a/spyder/plugins/editor/widgets/codeeditor.py
+++ b/spyder/plugins/editor/widgets/codeeditor.py
@@ -63,9 +63,10 @@
                                           FoldingPanel, IndentationGuide,
                                           LineNumberArea, PanelsManager,
                                           ScrollFlagArea)
-from spyder.plugins.editor.utils.editor import TextHelper, BlockUserData
+from spyder.plugins.editor.utils.editor import (TextHelper, BlockUserData,
+                                                TextBlockHelper)
 from spyder.plugins.editor.utils.debugger import DebuggerManager
-from spyder.plugins.editor.utils.folding import IndentFoldDetector
+from spyder.plugins.editor.utils.folding import IndentFoldDetector, FoldScope
 from spyder.plugins.editor.utils.kill_ring import QtKillRing
 from spyder.plugins.editor.utils.languages import ALL_LANGUAGES, CELL_LANGUAGES
 from spyder.plugins.editor.utils.lsp import request, handles, class_register
@@ -1599,11 +1600,15 @@ def get_linenumber_from_mouse_event(self, event):
 
         while block.isValid() and top < event.pos().y():
             block = block.next()
+            collapsed = TextBlockHelper.is_collapsed(block)
             if block.isVisible():  # skip collapsed blocks
                 top = bottom
                 bottom = top + self.blockBoundingRect(block).height()
                 line_number += 1
-
+            if collapsed:
+                scope = FoldScope(block)
+                start, end = scope.get_range(ignore_blank_lines=True)
+                line_number += (end - start)
         return line_number
 
     def select_lines(self, linenumber_pressed, linenumber_released):


Test patch: