Removing of trailing whitespace happens for selected lines, not all lines
A change was introduced, I believe it was in Notepad++ 8.4.9, that causes its command for "Trim Trailing Space" to only do that operation on selected text lines (if some selection is active at the time the command is executed), not on the entire file (as was behavior before 8.4.9).
This will cause editorconfig, which I believe invokes that command, to not do the editorconfig "spec" thing when some text is selected at the time of file save. Thus, one could have editorconfig configuration set to remove trailing space, have a selection active, save, and see lines that are not in the selected text region NOT have their trailing whitespace removed.
Using editorconfig for Notepad++ ver 0.4.0.0.
Do you have a reference? This kind of drastic API change is a bit unusual...
Reference:
Notepad++ user manual, https://npp-user-manual.org/docs/editing/#edit-menu
Thanks for the reference.
I think cancelling an active selection before saving should do the job. But I haven't look at it in much depth yet.
cancelling an active selection before saving should do the job
It would, but doing it really well would involve:
- take note of locations and types of active selection(s)
- invoke SCI_CLEARSELECTIONS
- restore original selection(s)
That can actually be somewhat complicated.
To me, it would be okay to just cancel any active selections and not worry about restoring them.
For me, just clearing the selection is the most logical choice. That is just one line of code. And with the possibility in N++ to use multiple selections it indeed could become complicated.
Would you always clear the selection when saving, or just when a trim trailing spaces should be executed? Me personally, I lean towards always clearing it. This is more consistent and predictable behavior.
IMO always clearing the selection is probably fine.
Latest Scintilla has an API to serialize and restore selections. I'm not sure whether this works when the file gets modified in between.
Hence I'd go with clearing a selection first.