diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-11-12 10:54:10 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2019-11-12 10:54:10 (GMT) |
commit | c8b53dc3d8f721ed8519aa5a35530a42fbfb9424 (patch) | |
tree | 9e6e28297b0083ccae965e44db76496aff55515d /Lib/idlelib/iomenu.py | |
parent | 733b9a308e3c49855888e2e12397ae56d831e780 (diff) | |
download | cpython-c8b53dc3d8f721ed8519aa5a35530a42fbfb9424.zip cpython-c8b53dc3d8f721ed8519aa5a35530a42fbfb9424.tar.gz cpython-c8b53dc3d8f721ed8519aa5a35530a42fbfb9424.tar.bz2 |
bpo-26353: IDLE adds an unneeded newline when saving a shell window (GH-17103)
Diffstat (limited to 'Lib/idlelib/iomenu.py')
-rw-r--r-- | Lib/idlelib/iomenu.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index b5533be..4b2833b 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -371,10 +371,7 @@ class IOBinding: return "break" def writefile(self, filename): - self.fixlastline() - text = self.text.get("1.0", "end-1c") - if self.eol_convention != "\n": - text = text.replace("\n", self.eol_convention) + text = self.fixnewlines() chars = self.encode(text) try: with open(filename, "wb") as f: @@ -387,6 +384,16 @@ class IOBinding: parent=self.text) return False + def fixnewlines(self): + "Return text with final \n if needed and os eols." + if (self.text.get("end-2c") != '\n' + and not hasattr(self.editwin, "interp")): # Not shell. + self.text.insert("end-1c", "\n") + text = self.text.get("1.0", "end-1c") + if self.eol_convention != "\n": + text = text.replace("\n", self.eol_convention) + return text + def encode(self, chars): if isinstance(chars, bytes): # This is either plain ASCII, or Tk was returning mixed-encoding @@ -426,11 +433,6 @@ class IOBinding: # declared encoding return BOM_UTF8 + chars.encode("utf-8") - def fixlastline(self): - c = self.text.get("end-2c") - if c != '\n': - self.text.insert("end-1c", "\n") - def print_window(self, event): confirm = tkMessageBox.askokcancel( title="Print", |