This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
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.
Description of the Change
When
toggleLineComments
is triggered, it will now correct the selection range to be within the comment delimiters.It will activate when
correctSelection
is true (it is hardcodedtrue
right now when toggling comments),If these conditions pass, it will then get the selection range and see if the head or tail needs to be moved. The range is adjusted, with
autoscroll
disabled to be consistent with exisiting behaviour (and it would be really annoying otherwise).Alternate Designs
I originally had it only work for empty selections, but decided this way is better.
It does seem quite long compared to what it's supposed to do though. I don't know how much of a problem that is.
This is applied to every selection in the editor when line comments are toggled. It's possible people only want it when there is just one selection / cursor. An interesting bug(?) is that when there's an even number of cursors on a line, it gets toggled twice, resulting in no change (this bug isn't related to this PR though).
Why Should This Be In Core?
It's a core mechanic
Benefits
Consistent with other text editors, and makes sense.
Possible Drawbacks
There's an interesting
...(this.getBufferRowRange() || [])
statement in the original version. I'm not sure whengetBufferRowRange
will return a falsey value, but that would shift the arguments of the function, moving theoptions
parameter tostart
.Originally, if it does evaluate to
[]
, no error is thrown but the top line would be comment toggled. That seems like a bug, but isn't related to this PR. I've changed the empty array to[null, null]
though, to ensure the argument positions are not changed.Verification Process
I tested manually, with the CSS grammar. I'll try to write proper tests after some feedback for changes, etc.
For now, this is what I'm expecting (where
|
is selection head/tail)Applicable Issues
Fix #4784