SublimeText / TrailingSpaces

Highlight trailing spaces and delete them in a flash.
MIT License
896 stars 94 forks source link

Add None check for single line files #152

Closed dnicolson closed 2 years ago

dnicolson commented 2 years ago

This pull request checks if the old value is None and sets it to [], which prevents the following error: "TypeError: object of type 'NoneType' has no len()"

The issue can be reproduced by entering the following text and saving: "a "

rchl commented 2 years ago

I believe this is not entirely the right place for the fix. The old argument is passed the value of the on_disk global. Why is it None in your case? I can see that this can be the case if the initial file opened on ST start is a scratch file and we try to delete trailing spaces in it. I would rather change the place that calls modified_lines_as_numbers to pass on_disk or [].

Also I can see that we don't always properly reset on_disk on switching from files saved on disk to scratch files so that can result in broken behavior when trying to delete trailing spaces in scratch files.

dnicolson commented 2 years ago

https://github.com/SublimeText/TrailingSpaces/pull/154