This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
CSS and HTML Line Comment #2133
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,24 +128,6 @@ define(function (require, exports, module) { | |
| }); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Invokes a language-specific line-comment/uncomment handler | ||
| * @param {?Editor} editor If unspecified, applies to the currently focused editor | ||
| */ | ||
| function lineComment(editor) { | ||
| editor = editor || EditorManager.getFocusedEditor(); | ||
| if (!editor) { | ||
| return; | ||
| } | ||
|
|
||
| var mode = editor.getModeForSelection(); | ||
|
|
||
| // Currently we only support languages with "//" commenting | ||
| if (mode === "javascript" || mode === "less") { | ||
| lineCommentSlashSlash(editor); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -388,6 +370,63 @@ define(function (require, exports, module) { | |
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Add or remove block-comment tokens to the selection, preserving selection | ||
| * and cursor position. Applies to the currently focused Editor. | ||
| * | ||
| * The implementation uses blockCommentPrefixSuffix, with the exception of the case where | ||
| * there is no selection on a uncommented and not empty line. In this case the whole lines gets | ||
| * commented in a bock-comment. | ||
| * | ||
| * @param {!Editor} editor | ||
| * @param {!String} prefix | ||
| * @param {!String} suffix | ||
| */ | ||
| function lineCommentPrefixSuffix(editor, prefix, suffix) { | ||
| var sel = editor.getSelection(), | ||
| selStart = sel.start, | ||
| selEnd = sel.end, | ||
| prefixExp = new RegExp("^" + StringUtils.regexEscape(prefix), "g"), | ||
| lineSelection = sel.start.ch === 0 && sel.end.ch === 0 && sel.start.line !== sel.end.line, | ||
| multipleLine = sel.start.line !== sel.end.line, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change these variable names to something like |
||
| lineLength = editor.document.getLine(sel.start.line).length; | ||
|
|
||
| // For a multiple line selection transform it to a multiple whole line selection | ||
| if (!lineSelection && multipleLine) { | ||
| selStart = {line: sel.start.line, ch: 0}; | ||
| selEnd = {line: sel.end.line + 1, ch: 0}; | ||
|
|
||
| // For one line selections, just start at column 0 and end at the end of the line | ||
| } else if (!lineSelection) { | ||
| selStart = {line: sel.start.line, ch: 0}; | ||
| selEnd = {line: sel.end.line, ch: lineLength}; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can nest these conditions so you are only checking the value of lineSelection once, and the code is a bit more clear: |
||
|
|
||
| // If the selection includes a comment or is already a line selection, delegate to Block-Comment | ||
| var ctx = TokenUtils.getInitialContext(editor._codeMirror, {line: selStart.line, ch: selStart.ch}); | ||
| var hasNext = _findNextBlockComment(ctx, selEnd, prefixExp); | ||
| if (ctx.token.className === "comment" || hasNext || lineSelection) { | ||
| blockCommentPrefixSuffix(editor, prefix, suffix, false); | ||
|
|
||
| } else { | ||
| // Set the new selection and comment it | ||
| editor.setSelection(selStart, selEnd); | ||
| blockCommentPrefixSuffix(editor, prefix, suffix, false); | ||
|
|
||
| // Restore the old selection taking into account the prefix change | ||
| if (multipleLine) { | ||
| sel.start.line++; | ||
| sel.end.line++; | ||
| } else { | ||
| sel.start.ch += prefix.length; | ||
| sel.end.ch += prefix.length; | ||
| } | ||
| editor.setSelection(sel.start, sel.end); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Invokes a language-specific block-comment/uncomment handler | ||
| * @param {?Editor} editor If unspecified, applies to the currently focused editor | ||
|
|
@@ -409,6 +448,28 @@ define(function (require, exports, module) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Invokes a language-specific line-comment/uncomment handler | ||
| * @param {?Editor} editor If unspecified, applies to the currently focused editor | ||
| */ | ||
| function lineComment(editor) { | ||
| editor = editor || EditorManager.getFocusedEditor(); | ||
| if (!editor) { | ||
| return; | ||
| } | ||
|
|
||
| var mode = editor.getModeForSelection(); | ||
|
|
||
| // Currently we only support languages with "//" commenting | ||
| if (mode === "javascript" || mode === "less") { | ||
| lineCommentSlashSlash(editor); | ||
| } else if (mode === "css") { | ||
| lineCommentPrefixSuffix(editor, "/*", "*/"); | ||
| } else if (mode === "html") { | ||
| lineCommentPrefixSuffix(editor, "<!--", "-->"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Duplicates the selected text, or current line if no selection. The cursor/selection is left | ||
|
|
||
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.
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.
typo: bock
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.
Reminder: fix this typo