RESOLVED INVALID 91382
Web Inspector: Comment/uncomment line(s) by pressing Cmd + /
https://bugs.webkit.org/show_bug.cgi?id=91382
Summary Web Inspector: Comment/uncomment line(s) by pressing Cmd + /
Nikita Vasilyev
Reported 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.
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-
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
Proposed bug fix. Missing expected results for tests. (11.51 KB, patch)
2012-09-27 10:24 PDT, Mihai Balan
no flags
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-
Pavel Feldman
Comment 1 2012-07-16 09:47:22 PDT
Sounds good to me. Do you have a patch?
Nikita Vasilyev
Comment 2 2012-07-16 10:32:03 PDT
Not yet. I’m going to start working on it.
Mihai Balan
Comment 3 2012-09-21 05:50:37 PDT
Given that Nikita gave no sign since July, I'll give it a try with this bug :)
Nikita Vasilyev
Comment 4 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.
Pavel Feldman
Comment 5 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.
Nikita Vasilyev
Comment 6 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?
Pavel Feldman
Comment 7 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.
Mihai Balan
Comment 8 2012-09-21 08:22:41 PDT
Created attachment 165135 [details] Proposed bug fix. Replaced Cmd + / from Pause script to Toggle code comment.
Nikita Vasilyev
Comment 9 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.
Andrey Adaikin
Comment 10 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;
Andrey Adaikin
Comment 11 2012-09-24 09:39:28 PDT
Also how about adding "// " (with a space at the end) instead of "//"?
Mihai Balan
Comment 12 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).
Mihai Balan
Comment 13 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 :)
Mihai Balan
Comment 14 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?
WebKit Review Bot
Comment 15 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.
Mihai Balan
Comment 16 2012-09-27 10:24:07 PDT
Created attachment 166027 [details] Proposed bug fix. Missing expected results for tests.
Mihai Balan
Comment 17 2012-09-27 10:31:25 PDT
Created attachment 166030 [details] Proposed bug fix. Missing expected results for tests. Minor style fixes.
Build Bot
Comment 18 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
WebKit Review Bot
Comment 19 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
Alexander Pavlov (apavlov)
Comment 20 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 :)
Andrey Adaikin
Comment 21 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 /* ... */
Pavel Feldman
Comment 22 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.
Mihai Balan
Comment 23 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)?
Andrey Adaikin
Comment 24 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.
Mihai Balan
Comment 25 2012-10-01 04:57:58 PDT
> > As far as I'm concerned, r- is for code duplication. OK, I'll fix that :)
Jan Keromnes
Comment 26 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.
Brian Burg
Comment 27 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.
Note You need to log in before you can comment on or make changes to this bug.