Repository: spyder-ide/spyder

Issue:
Goto previous cell behaviour is different than other IDEs
## Description of your problem
Goto previous cell should go to previous cell only when the cursor is at the first line of the cell (the cell marker), otherwise it should go to the beginning of the current cell (same as in MATLAB, Atom etc.)

While indeed "goto previous cell" is the definition of the action, its actual action should be dependant on the cursor location.

**What steps will reproduce the problem?**

1. Create 2 cells with several lines each
2. Place the cursor at the second line (or any other line except the cell marker) of the second cell
3. Select Goto previous cell 

**What is the expected output? What do you see instead?**
The cursor should be placed at the current cell marker rather than the cell marker of the previous cell

**Please provide any additional information below**


## Versions and main components

* Spyder Version: spyder from GIT obtained on 1/Jun/2017
* Python Version: 3.5.2
* Qt Version:5.6.2
* PyQt Version:5.6
* Operating system:Linux



Discussion:
Thanks for reporting. @dalthviz, let's make our cell go to next/previous shortcuts to follow the same behavior as in Matlab.

Resolving patch:
diff --git a/spyder/widgets/sourcecode/base.py b/spyder/widgets/sourcecode/base.py
--- a/spyder/widgets/sourcecode/base.py
+++ b/spyder/widgets/sourcecode/base.py
@@ -793,25 +793,19 @@ def go_to_previous_cell(self):
         cursor = self.textCursor()
         cur_pos = prev_pos = cursor.position()
 
-        # Move to the begining of the cell
-        while not self.is_cell_separator(cursor):
-            # Moving to the previous code cell
+        if self.is_cell_separator(cursor):
+            # Move to the previous cell
             cursor.movePosition(QTextCursor.PreviousBlock)
-            prev_pos = cur_pos
-            cur_pos = cursor.position()
-            if cur_pos == prev_pos:
-                return
+            cur_pos = prev_pos = cursor.position()
 
-        # Move to the previous cell
-        cursor.movePosition(QTextCursor.PreviousBlock)
-        cur_pos = prev_pos = cursor.position()
         while not self.is_cell_separator(cursor):
-            # Moving to the previous code cell
+            # Move to the previous cell or the beginning of the current cell
             cursor.movePosition(QTextCursor.PreviousBlock)
             prev_pos = cur_pos
             cur_pos = cursor.position()
             if cur_pos == prev_pos:
                 return
+
         self.setTextCursor(cursor)
 
     def get_line_count(self):


Test patch:
diff --git a/spyder/widgets/tests/test_editor.py b/spyder/widgets/tests/test_editor.py
--- a/spyder/widgets/tests/test_editor.py
+++ b/spyder/widgets/tests/test_editor.py
@@ -191,6 +191,10 @@ def test_advance_cell(editor_cells_bot):
     # cursor at the end of the file
     assert editor.get_cursor_line_column() == (10, 0)
 
+    # advance backwards to the begining of the 3rd cell
+    editor_stack.advance_cell(reverse=True)
+    assert editor.get_cursor_line_column() == (6, 0)
+
     # advance backwards to 2nd cell
     editor_stack.advance_cell(reverse=True)
     assert editor.get_cursor_line_column() == (3, 0)