summaryrefslogtreecommitdiff
path: root/Lib/idlelib/format.py
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2019-11-24 16:29:29 -0500
committerGitHub <noreply@github.com>2019-11-24 16:29:29 -0500
commit6bf644ec82f14cceae68278dc35bafb00875efae (patch)
tree79a913bdabfec4c9d3c30ec112f185336ce34eb0 /Lib/idlelib/format.py
parent6f03b236c17c96bc9f8a004ffa7e7ae0542e9cac (diff)
downloadcpython-git-6bf644ec82f14cceae68278dc35bafb00875efae.tar.gz
bpo-38862: IDLE Strip Trailing Whitespace fixes end newlines (GH-17366)
Extra newlines are removed at the end of non-shell files. If the file only has newlines after stripping other trailing whitespace, all are removed, as is done by patchcheck.py.
Diffstat (limited to 'Lib/idlelib/format.py')
-rw-r--r--Lib/idlelib/format.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/idlelib/format.py b/Lib/idlelib/format.py
index 2b09805657..4b57a182c9 100644
--- a/Lib/idlelib/format.py
+++ b/Lib/idlelib/format.py
@@ -408,6 +408,16 @@ class Rstrip: # 'Strip Trailing Whitespace" on "Format" menu.
if cut < raw:
text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
+ if (text.get('end-2c') == '\n' # File ends with at least 1 newline;
+ and not hasattr(self.editwin, 'interp')): # & is not Shell.
+ # Delete extra user endlines.
+ while (text.index('end-1c') > '1.0' # Stop if file empty.
+ and text.get('end-3c') == '\n'):
+ text.delete('end-3c')
+ # Because tk indexes are slice indexes and never raise,
+ # a file with only newlines will be emptied.
+ # patchcheck.py does the same.
+
undo.undo_block_stop()