-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fixing several Block and Line Comment issues #2342
Conversation
A few issues I noticed in testing:
|
If you are allowed to block comment with any selection of a mix of code + line comment, even when doing a block comment might uncomment part of the line comments, it makes things easier to check. This should then work for all the cases mentioned above. |
I've created a big suite of unit tests for line comment that I hope will be helpful: see pflynn/block-comment-unittests (it's not on master yet since they're not all passing). It's still hitting two things that I think are bugs, but almost all the tests pass with your latest commit. One problem seems to with looking at the char or token after the end of the selection:
The other is related to selections that end at ch:0. The behavior varies depending on what's on that line, when it probably shouldn't matter (because the selection doesn't include any chars from that line; just the CR ending the previous line).
If you'd like to use my unit tests for testing your changes, you could use a procedure like this:
(This way you can use my tests before they've landed in master, without getting them stuck in your branch & thus your pull request) |
I fixed the code so that it passed the 3 failed unit tests and every other test. |
@@ -303,9 +307,9 @@ define(function (require, exports, module) { | |||
if (editor.posWithinRange(start, sel.start, sel.end)) { | |||
// Start searching at the next token, if there is one. | |||
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx); | |||
result = !result || _findNextBlockComment(ctx, sel.end, prefixExp); | |||
found = !result || _findNextBlockComment(ctx, sel.end, prefixExp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be written more simply as just:
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx) &&
_findNextBlockComment(ctx, sel.end, prefixExp);
...and then only check for result
below. I'm pretty sure this is logically equivalent (short circuiting guarantees that _findNextBlockComment() won't run if the first moveSkippingWhitespace() returns false), and all the unit tests still pass if I change this. Although it's a little confusing that the first clause has side-effects on ctx
which is then re-used in the 2nd clause, if you wanted to make that more explicit I'd suggest something like this:
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx);
result = result && _findNextBlockComment(ctx, sel.end, prefixExp);
or even more explicit:
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx);
if (result) {
result = _findNextBlockComment(ctx, sel.end, prefixExp);
}
@TomMalbran: Done reviewing. Looks good except for those two nits about the boolean operation. Btw -- unrelated to this pull request -- I was wondering if you could tell me more about the block of code that starts with |
Yes I am using that to check if the start of the selection is in a whitespace before the text. So then it can be used to uncomment line comments of multiple block comments, but when the start of the selection is after the first line of the block comment and before the start of the line, since here it still has |
Changes done. |
Looks great -- thanks again! Merging now (whew!) |
Fixing several Block and Line Comment issues
This pull request fixes both issues mentioned in #2339, one of them being a line comment issue and the other a block comment issue and the 6/7 and 9/10 inconsistency mentioned in #2337 since that really wasn't an intended behavior.