mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
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.
This commit is contained in:
parent
6f03b236c1
commit
6bf644ec82
7 changed files with 68 additions and 40 deletions
|
|
@ -408,6 +408,16 @@ def do_rstrip(self, event=None):
|
|||
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()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue