Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Zelnes
Copy link

@Zelnes Zelnes commented Mar 5, 2020

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

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions

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:

  • Remove all trailing whitespaces when saving
  • Clear previous line if needed when inserting a newline

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.

@Zelnes Zelnes force-pushed the wip/remove-whitespaces-on-new-lines-non-edited-rebase branch 2 times, most recently from 248f51b to 626c982 Compare March 5, 2020 19:51
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant