diff --git a/spyder/plugins/editor/panels/codefolding.py b/spyder/plugins/editor/panels/codefolding.py index 982f5ea549a..023d7e3942f 100644 --- a/spyder/plugins/editor/panels/codefolding.py +++ b/spyder/plugins/editor/panels/codefolding.py @@ -709,11 +709,13 @@ def _expand_selection(self): start_line in self.folding_regions and self.folding_status[start_line] ): - end_line = self.folding_regions[start_line] + 1 + end_line = self.folding_regions[start_line] if cursor.hasSelection(): tc = TextHelper(self.editor).select_lines( start_line, end_line) + tc.movePosition(tc.MoveOperation.NextBlock, + tc.MoveMode.KeepAnchor) if tc.selectionStart() > cursor.selectionStart(): start = cursor.selectionStart() diff --git a/spyder/plugins/editor/widgets/codeeditor/tests/test_folding.py b/spyder/plugins/editor/widgets/codeeditor/tests/test_folding.py index ef0f721a4bd..86552025a21 100644 --- a/spyder/plugins/editor/widgets/codeeditor/tests/test_folding.py +++ b/spyder/plugins/editor/widgets/codeeditor/tests/test_folding.py @@ -28,7 +28,7 @@ def myfunc2(): 3 , 4] # Arbitary Code x[0] = 2 # Desired break print(x[1]) # Arbitary Code - +# don't delete this comment responses = { 100: ('Continue', 'Request received, please continue'), 101: ('Switching Protocols','Switching to new protocol'), @@ -182,6 +182,9 @@ def fold_and_delete_region(key): assert "print" not in editor.toPlainText() assert editor.blockCount() == 31 + # Check line after folded region was not removed + assert "# don't delete this comment" in editor.toPlainText() + # Press Ctrl+Z qtbot.keyClick(editor, Qt.Key_Z, Qt.ControlModifier) @@ -193,6 +196,9 @@ def fold_and_delete_region(key): assert "print" not in editor.toPlainText() assert editor.blockCount() == 31 + # Check line after folded region was not removed + assert "# don't delete this comment" in editor.toPlainText() + # Press Ctrl+Z again qtbot.keyClick(editor, Qt.Key_Z, Qt.ControlModifier)