Repository: spyder-ide/spyder

Issue:
Trailing spaces are being removed on line change even if the option is unset in preferences
## Problem Description

In the editor, if I move down from an indented line to another indented line, then move back up, the line above is no longer indented.

I tried to  disable the option "automatically strip trailing spaces on changed lines" in preferences->editor->source code, but the spaces are still removed.


### What steps reproduce the problem?

1. Create a new function.
2. Press enter to go to the next line, which should be indented.
3. Press enter again, to go to a second indented line.
4. Press up to move back up to the previous line, and it is no longer indented and no longer contains any spaces.

### What is the expected output? What do you see instead?

I dont expect the first lines to lose their indentations. If I add "show spaces" I can see the first line losses it's indentations when I press return the second time. I would like.

```
def main():
    
    
```
(The spaces are there, but I am not sure of a good way to show them on this interface.)

Quite possibly, I am not setting/unsetting the correct option.

## Versions
Spder 4.0.0b5

Python 3.6.8 64-bit  
Qt 5.12.4  
PyQt5 5.12.3  
Linux 3.10.0-1062.el7.x86_64
Centos 7 




Discussion:
@odinsbane Thank you for the testing out Spyder beta!

This is a known issue documented on #10146, but I'll leave this issue open as it is more directly about the setting.



Resolving patch:
diff --git a/spyder/config/main.py b/spyder/config/main.py
--- a/spyder/config/main.py
+++ b/spyder/config/main.py
@@ -222,7 +222,7 @@
               'autosave_enabled': True,
               'autosave_interval': 60,
               'docstring_type': 'Numpydoc',
-              'strip_trailing_spaces_on_modify': True,
+              'strip_trailing_spaces_on_modify': False,
               }),
             ('historylog',
              {
@@ -592,4 +592,4 @@
 #    or if you want to *rename* options, then you need to do a MAJOR update in
 #    version, e.g. from 3.0.0 to 4.0.0
 # 3. You don't need to touch this value if you're just adding a new option
-CONF_VERSION = '53.0.0'
+CONF_VERSION = '53.1.0'
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
@@ -1282,7 +1282,7 @@ def set_tab_mode(self, enable):
 
     def set_strip_mode(self, enable):
         """
-        Strip all trailing spaces if enabled, else only strip on auto-indents.
+        Strip all trailing spaces if enabled.
         """
         self.strip_trailing_spaces_on_modify = enable
 
@@ -3475,7 +3475,10 @@ def insert_text(event):
                   self.autoinsert_colons():
                     self.textCursor().beginEditBlock()
                     self.insert_text(':' + self.get_line_separator())
-                    self.fix_and_strip_indent()
+                    if self.strip_trailing_spaces_on_modify:
+                        self.fix_and_strip_indent()
+                    else:
+                        self.fix_indent()
                     self.textCursor().endEditBlock()
                 elif self.is_completion_widget_visible():
                     self.select_completion_list()
@@ -3496,7 +3499,11 @@ def insert_text(event):
 
                     self.textCursor().beginEditBlock()
                     insert_text(event)
-                    self.fix_and_strip_indent(comment_or_string=cmt_or_str)
+                    if self.strip_trailing_spaces_on_modify:
+                        self.fix_and_strip_indent(
+                            comment_or_string=cmt_or_str)
+                    else:
+                        self.fix_indent(comment_or_string=cmt_or_str)
                     self.textCursor().endEditBlock()
         elif key == Qt.Key_Insert and not shift and not ctrl:
             self.setOverwriteMode(not self.overwriteMode())


Test patch:
diff --git a/spyder/plugins/editor/widgets/tests/test_codeeditor.py b/spyder/plugins/editor/widgets/tests/test_codeeditor.py
--- a/spyder/plugins/editor/widgets/tests/test_codeeditor.py
+++ b/spyder/plugins/editor/widgets/tests/test_codeeditor.py
@@ -91,7 +91,7 @@ def test_editor_log_lsp_handle_errors(editorbot, capsys):
     "input_text, expected_text, keys, strip_all",
     [
         ("for i in range(2): ",
-         "for i in range(2): \n\n     \n    ",
+         "for i in range(2): \n    \n     \n    ",
          [Qt.Key_Enter, Qt.Key_Enter, ' ', Qt.Key_Enter],
          False),
         ('for i in range(2): ',
@@ -135,7 +135,7 @@ def test_editor_log_lsp_handle_errors(editorbot, capsys):
          [Qt.Key_Enter, Qt.Key_Enter],
          True),
         ('def fun():\n    """fun',
-         'def fun():\n    """fun\n\n    ',
+         'def fun():\n    """fun\n    \n    ',
          [Qt.Key_Enter, Qt.Key_Enter],
          False),
         ("('🚫')",