Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python Console] Fix duplicated newline on save (windows) #52188

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions python/console/console_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down