From 3a5dc125c21ad0c13f615fe6da73ee0a56c58722 Mon Sep 17 00:00:00 2001 From: sphh Date: Sat, 14 Aug 2021 08:15:18 +0000 Subject: [PATCH] Solves pasting of one line + newline into the codeeditor PR #16164 fixed bug #16159, where the indentation of code pasted into the editor was lost. This failed the border case, where just one line + newline was pasted (https://github.com/spyder-ide/spyder/issues/16159#issuecomment-898484641 ff). This PR solves this. --- spyder/plugins/editor/widgets/codeeditor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py index ec3e0be93be..966297b6ab6 100644 --- a/spyder/plugins/editor/widgets/codeeditor.py +++ b/spyder/plugins/editor/widgets/codeeditor.py @@ -2833,10 +2833,12 @@ def paste(self): preceding_text) # Make sure the code is not flattened - max_dedent = min( - [self.get_line_indentation(line) - for line in remaining_lines if line.strip() != ""]) - lines_adjustment = max(lines_adjustment, -max_dedent) + indentations = [ + self.get_line_indentation(line) + for line in remaining_lines if line.strip() != ""] + if indentations: + max_dedent = min(indentations) + lines_adjustment = max(lines_adjustment, -max_dedent) # Get new text remaining_lines = [