Bug 91382 - Web Inspector: Comment/uncomment line(s) by pressing Cmd + /
Summary: Web Inspector: Comment/uncomment line(s) by pressing Cmd + /
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Mihai Balan
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-16 06:31 PDT by Nikita Vasilyev
Modified: 2014-12-12 14:37 PST (History)
14 users (show)

See Also:


Attachments
Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment. (4.58 KB, patch)
2012-09-21 08:22 PDT, Mihai Balan
aandrey: review-
Details | Formatted Diff | Diff
Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment. Missing expected results for tests. (11.39 KB, patch)
2012-09-27 10:10 PDT, Mihai Balan
no flags Details | Formatted Diff | Diff
Proposed bug fix. Missing expected results for tests. (11.51 KB, patch)
2012-09-27 10:24 PDT, Mihai Balan
no flags Details | Formatted Diff | Diff
Proposed bug fix. Missing expected results for tests. (11.53 KB, patch)
2012-09-27 10:31 PDT, Mihai Balan
pfeldman: review-
buildbot: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2012-07-16 06:31:13 PDT
⌘/ (Ctrl/ on non-Mac) comments/uncomments lines in all code editors I’ve tested (Xcode, IntelliJ IDEA, Sublime Text 2, Textmate).

In Web Inspector it currently pause/continue script execution. I believe, it came from Firebug that doesn’t support code editing. I suggest to change this shorthand to something else. For example, Xcode uses Ctrl + Cmd + Y.
Comment 1 Pavel Feldman 2012-07-16 09:47:22 PDT
Sounds good to me. Do you have a patch?
Comment 2 Nikita Vasilyev 2012-07-16 10:32:03 PDT
Not yet. I’m going to start working on it.
Comment 3 Mihai Balan 2012-09-21 05:50:37 PDT
Given that Nikita  gave no sign since July, I'll give it a try with this bug :)
Comment 4 Nikita Vasilyev 2012-09-21 06:34:50 PDT
Go ahead, Mihai.

Few things to consider:

It should work with both the current editor and CodeMirror.

Sublime Text adds adds "//" at the current indent level:
if (1)
    // foo

Conversely, Xcode and IntelliJ IDEA adds "//" at the beginning of the line, e.g.:

if (1)
//    foo

I’m fine with either of them as long as it doesn’t comment a line twice:

if (1)
//    // foo

Xcode suffers from it.
Comment 5 Pavel Feldman 2012-09-21 06:43:52 PDT
> It should work with both the current editor and CodeMirror.

Correction, CodeMirror is a non-goal for Web Inspector (at least not in its current state). I'll remove the experiment.
Comment 6 Nikita Vasilyev 2012-09-21 06:47:25 PDT
(In reply to comment #5)
> > It should work with both the current editor and CodeMirror.
> 
> Correction, CodeMirror is a non-goal for Web Inspector (at least not in its current state). I'll remove the experiment.

Why so? Any details somewhere?
Comment 7 Pavel Feldman 2012-09-21 06:57:26 PDT
v2 had gutter problems we could not afford (https://github.com/marijnh/CodeMirror/issues/730). When v3 is ready, we will perform another assessment.
Comment 8 Mihai Balan 2012-09-21 08:22:41 PDT
Created attachment 165135 [details]
Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment.
Comment 9 Nikita Vasilyev 2012-09-21 12:59:39 PDT
Selection moves 2 characters on the left after commenting out a line. Screencast: http://www.screenr.com/O338.
Also, on 17 second I select one whole line but it comments out the next one too.
Comment 10 Andrey Adaikin 2012-09-24 09:37:49 PDT
Comment on attachment 165135 [details]
Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment.

View in context: https://bugs.webkit.org/attachment.cgi?id=165135&action=review

> Source/WebCore/inspector/front-end/DefaultTextEditor.js:1594
> +            if (line.match(commentRegEx)) {

this will not work for multiple lines with comments:

var a = 1;
// a comment
var b = 2;

will become:

// var a = 1;
a comment
// var b = 2;

while should be:

// var a = 1;
// // a comment
// var b = 2;

> Source/WebCore/inspector/front-end/DefaultTextEditor.js:1606
> +    },

return true;
Comment 11 Andrey Adaikin 2012-09-24 09:39:28 PDT
Also how about adding "// " (with a space at the end) instead of "//"?
Comment 12 Mihai Balan 2012-09-24 10:00:06 PDT
(In reply to comment #11)
> Also how about adding "// " (with a space at the end) instead of "//"?

Sounds doable :) What should happen however when removing the comments from the beginning of the line? Should it remove only "//"? Only "// "? Both?
One of the reasons I opted for "//" is that it preserves the most of the original code when adding/removing (even though there are cases when after a comment/uncomment the source will not be same anymore).
Comment 13 Mihai Balan 2012-09-24 11:32:49 PDT
Comment on attachment 165135 [details]
Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment.

View in context: https://bugs.webkit.org/attachment.cgi?id=165135&action=review

>> Source/WebCore/inspector/front-end/DefaultTextEditor.js:1594
>> +            if (line.match(commentRegEx)) {
> 
> this will not work for multiple lines with comments:
> 
> var a = 1;
> // a comment
> var b = 2;
> 
> will become:
> 
> // var a = 1;
> a comment
> // var b = 2;
> 
> while should be:
> 
> // var a = 1;
> // // a comment
> // var b = 2;

I have already discussed this aspect on IRC with apavolov and a new patch is in works, complete with unit tests and a some refactoring of the code :)
Comment 14 Mihai Balan 2012-09-27 10:10:12 PDT
Created attachment 166026 [details]
Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment. Missing expected results for tests.

Doesn't have expected results for the test. What's the recommended way of producing the expected results?
Comment 15 WebKit Review Bot 2012-09-27 10:13:07 PDT
Attachment 166026 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'LayoutTests/ChangeLog', u'LayoutTests/insp..." exit_code: 1
LayoutTests/ChangeLog:1:  ChangeLog entry has no bug number  [changelog/bugnumber] [5]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 16 Mihai Balan 2012-09-27 10:24:07 PDT
Created attachment 166027 [details]
Proposed bug fix. Missing expected results for tests.
Comment 17 Mihai Balan 2012-09-27 10:31:25 PDT
Created attachment 166030 [details]
Proposed bug fix. Missing expected results for tests.

Minor style fixes.
Comment 18 Build Bot 2012-09-27 13:08:46 PDT
Comment on attachment 166030 [details]
Proposed bug fix. Missing expected results for tests.

Attachment 166030 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14059004

New failing tests:
inspector/editor/comment-toggling.html
Comment 19 WebKit Review Bot 2012-09-27 14:19:58 PDT
Comment on attachment 166030 [details]
Proposed bug fix. Missing expected results for tests.

Attachment 166030 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/14056048

New failing tests:
inspector/editor/comment-toggling.html
Comment 20 Alexander Pavlov (apavlov) 2012-09-27 22:04:16 PDT
(In reply to comment #14)
> Created an attachment (id=166026) [details]
> Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment. Missing expected results for tests.
> 
> Doesn't have expected results for the test. What's the recommended way of producing the expected results?

When you run a test with missing expectations, DRT will write down the "*-expected.txt" file for you, so you just need to scrutinize it and make sure the results are correct. And don't forget to add it to your patch :)
Comment 21 Andrey Adaikin 2012-09-28 01:24:41 PDT
Comment on attachment 166030 [details]
Proposed bug fix. Missing expected results for tests.

View in context: https://bugs.webkit.org/attachment.cgi?id=166030&action=review

> Source/WebCore/inspector/front-end/DefaultTextEditor.js:1581
> +    _commentLines: function(range, commentRegEx)

So, we already have _indentLines and _unindentLines methods, which do almost the same work (just a regexp is different). I'd guess there must be much of the code that can be reused.

Also, I'd move out these fancy IDE-like code transformations from the basic editor functionality into a separate class, and ideally make it work with any TextEditor implementation.

Also, we should look at how Xcode comments the lines. For example this test case:

//line1
// line2
 //line3

  //line4
   //            line5

I don't have an Xcode by my hand, but Sublime for example, would uncomment all lines first, and then comment in the following way:

// line1
// line2
//  line3

//   line4
//               line5

(Note, that empty lines are ignored, unlike your implementation).

Also, we'll probably want Ctrl+Shift+/ to add block comments /* ... */
Comment 22 Pavel Feldman 2012-09-28 05:01:35 PDT
Comment on attachment 166030 [details]
Proposed bug fix. Missing expected results for tests.

r- per Andrey's comments.
Comment 23 Mihai Balan 2012-09-28 09:22:51 PDT
Comment on attachment 166030 [details]
Proposed bug fix. Missing expected results for tests.

View in context: https://bugs.webkit.org/attachment.cgi?id=166030&action=review

>> Source/WebCore/inspector/front-end/DefaultTextEditor.js:1581
>> +    _commentLines: function(range, commentRegEx)
> 
> So, we already have _indentLines and _unindentLines methods, which do almost the same work (just a regexp is different). I'd guess there must be much of the code that can be reused.
> 
> Also, I'd move out these fancy IDE-like code transformations from the basic editor functionality into a separate class, and ideally make it work with any TextEditor implementation.
> 
> Also, we should look at how Xcode comments the lines. For example this test case:
> 
> //line1
> // line2
>  //line3
> 
>   //line4
>    //            line5
> 
> I don't have an Xcode by my hand, but Sublime for example, would uncomment all lines first, and then comment in the following way:
> 
> // line1
> // line2
> //  line3
> 
> //   line4
> //               line5
> 
> (Note, that empty lines are ignored, unlike your implementation).
> 
> Also, we'll probably want Ctrl+Shift+/ to add block comments /* ... */

First of all, is really block commenting in the scope for this bug? Because I think it needs even more specifying than line comments (e.g. should the editor look for block comments outside the selection? Should it look for comments inside the selection but smaller than it? What should happen if the beginning of the selection is on a line that is commented with //? etc.)

Finally, what are the actual r- items (besides the missing test expectations) and what are nice-to-have-s (possibly extractable in a different patch)?
Comment 24 Andrey Adaikin 2012-10-01 01:37:37 PDT
(In reply to comment #23)
> (From update of attachment 166030 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=166030&action=review
> 
> >> Source/WebCore/inspector/front-end/DefaultTextEditor.js:1581
> >> +    _commentLines: function(range, commentRegEx)
> > 
> > So, we already have _indentLines and _unindentLines methods, which do almost the same work (just a regexp is different). I'd guess there must be much of the code that can be reused.
> > 
> > Also, I'd move out these fancy IDE-like code transformations from the basic editor functionality into a separate class, and ideally make it work with any TextEditor implementation.
> > 
> > Also, we should look at how Xcode comments the lines. For example this test case:
> > 
> > //line1
> > // line2
> >  //line3
> > 
> >   //line4
> >    //            line5
> > 
> > I don't have an Xcode by my hand, but Sublime for example, would uncomment all lines first, and then comment in the following way:
> > 
> > // line1
> > // line2
> > //  line3
> > 
> > //   line4
> > //               line5
> > 
> > (Note, that empty lines are ignored, unlike your implementation).
> > 
> > Also, we'll probably want Ctrl+Shift+/ to add block comments /* ... */
> 
> First of all, is really block commenting in the scope for this bug? Because I think it needs even more specifying than line comments (e.g. should the editor look for block comments outside the selection? Should it look for comments inside the selection but smaller than it? What should happen if the beginning of the selection is on a line that is commented with //? etc.)
> 
> Finally, what are the actual r- items (besides the missing test expectations) and what are nice-to-have-s (possibly extractable in a different patch)?

As far as I'm concerned, r- is for code duplication.
Comment 25 Mihai Balan 2012-10-01 04:57:58 PDT
> 
> As far as I'm concerned, r- is for code duplication.

OK, I'll fix that :)
Comment 26 Jan Keromnes 2012-10-17 09:32:11 PDT
Sorry for the somewhat unrelated and belated comment.

(In reply to comment #5)
> Correction, CodeMirror is a non-goal for Web Inspector (at least not in its current state). I'll remove the experiment.

(In reply to comment #7)
> v2 had gutter problems we could not afford (https://github.com/marijnh/CodeMirror/issues/730). When v3 is ready, we will perform another assessment.

Pavel please don't delete the experiment just yet, I have an upcoming patch to update to v3. It should be stable soon, will fix the #94118 gutter problem, and should help implementing #94056 and #94062 a great deal.

Also, implementing `Cmd + /` in the experiment shouldn't be a problem.
Comment 27 Brian Burg 2014-12-12 14:37:35 PST
Closing as invalid, as this bug pertains to the old inspector UI and/or its tests.
Please file a new bug (https://www.webkit.org/new-inspector-bug) if the bug/feature/issue is still relevant to WebKit trunk.