This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Enhance the mecanism that removes whitespaces on newline insertion #190
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the cursor reaches a line that contains only whitespaces, this line
is stored and if an edition happens elsewhere, the stored lines are
checked and cleaned if they still contains only whitespaces.
This tries to copy SublimeText's feature
Preface
I'm not an english speaker, please consider it while reading my explanations and code.
Requirements
Description of the Change
In this PR, I tried to copy SublimeText's feature that remove trailing whitespaces when the cursor leaves a line that contain only whitespaces.
In order to achieve this feature, I firstly sliced the OnSave feature:
I suggest at least this change for the PR, because I think it makes more sense to separate a live edition feature from an OnSave one
Also, I used an
Array
to manage subscriptions, to avoid code duplication and make it easier to subscribe to any event.The need was to benefit from the live
"Clearing"
feature, without the OnSave one (for example, I often work on code that doesn't belong to me and that may contain trailing whitespaces where I don't need to edit).Alternate Designs
None
Benefits
When a user will insert several newlines at a time, no matter how many cursors there are, there won't be whitespaces lines left behind.
This will avoid backtracking to lines where there were still whitespaces lines, and remove them.
Also, if you were to insert a newline for a visual sake, you could directly leave this/these line(s) and edit elsewhere, the blanks will be removed automatically.
This is quite similar to SublimeText feature.
It support multiple cursors and also it will react when you paste text.
Possible Drawbacks
History management is probably the less effective change brought by this change, it may alter something else. It tried to catch issues with the tests, but I may missed so test cases
Applicable Issues
Footnote
In the spec section, I moved an
it
from the OnSave feature into the newly added one, because it has more sense. I did not alter it.