From b641186ac82a832bc4fc7de81a0e852610e5f051 Mon Sep 17 00:00:00 2001 From: Yoann Quenach de Quivillic Date: Sun, 12 Mar 2023 09:35:20 +0100 Subject: [PATCH] Fix duplicated newline on save (windows) --- python/console/console_editor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/console/console_editor.py b/python/console/console_editor.py index 80cf7a594bbb..5aa7ea7275c4 100644 --- a/python/console/console_editor.py +++ b/python/console/console_editor.py @@ -301,7 +301,9 @@ def toggleFindWidget(self): def createTempFile(self): name = tempfile.NamedTemporaryFile(delete=False).name - Path(name).write_text(self.text(), encoding='utf-8') + # Need to use newline='' to avoid adding extra \r characters on Windows + with open(name, 'w', encoding='utf-8', newline='') as f: + f.write(self.text()) return name def runScriptCode(self): @@ -427,7 +429,9 @@ def save(self, filename=None): self.pythonconsole.callWidgetMessageBarEditor(msgText, 0, True) # Save the new contents - Path(self.path).write_text(self.text(), encoding='utf-8') + # Need to use newline='' to avoid adding extra \r characters on Windows + with open(self.path, 'w', encoding='utf-8', newline='') as f: + f.write(self.text()) tabwidget.setTabTitle(index, Path(self.path).name) tabwidget.setTabToolTip(index, self.path) self.setModified(False)