-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add new comments preference. Support indent block comments on line co… #13254
Conversation
@ficristo I think it's more trouble that it's worth to deprecate the |
@ficristo Also, I think #13169 can be fixed without adding a new preference as follows: For languages that do not have a different line comment format (such as HTML), the block comment format is used on a single line. In that case, the But I can also see the value of having a separate indenting preference for block comments. |
I would find |
I still need to test it a bit more |
It should be ready. |
…ine comment command
Seeing weird results for block comment, indentBlockComment=true, and cursor at start of line (i.e. line not selected). Before: <p>lkj wlekjr wlkerj lwkejr wlke lqkwje lkqjwe lkqwje lwkqje lq</p> After: --<!--> <p>lkj wlekjr wlkerj lwkejr wlke lqkwje lkqjwe lkqwje lwkqje lq</p> |
src/editor/EditorCommandHandlers.js
Outdated
if (indentBlockComment) { | ||
var endCh = _firstNotWs(doc, sel.end.line - 1); | ||
editGroup.push({ | ||
text: _.repeat(" ", endCh) + suffix + "\n", |
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.
Can't always insert spaces -- need to use indent preference here in case it's Tabs.
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.
Great catch! Fixed.
src/editor/Editor.js
Outdated
@@ -2709,6 +2713,27 @@ define(function (require, exports, module) { | |||
}; | |||
|
|||
/** | |||
* Returns true if blockCommentIndent is enabled for the specified or current file |
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.
First line of this comment is true for "get", but not "set".
@ficristo Done with review. Found a couple cases that don't work as expected, but mostly working as advertised. Tests pass for me on Mac 10.12. |
Also, all Preferences should be listed in wiki here: Please add |
I cannot reproduce the issue above about the html. Is that the full snippet? |
@ficristo To repro this bug, make sure cursor is at start of line, or in middle of indent. Doesn't seem to happen if cursor is immediately before start tag. I also notice weird results when cursor is in middle of tag contents. Comment is added from start of tag to cursor positioin, which causes invalid HTML: <!--<p>lkj wlekjr wlkerj lwkejr wlke--> lqkwje lkqjwe lkqwje lwkqje lq</p> |
@ficristo Here's a simple page where I'm also seeing problem on <!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<p>one two three</p>
</body>
</html> |
|
Initially I thought that |
Yes, that's the case when either start or end cursor is in middle of line. I agree that behavior should not change. But the other case is when the selection only contains full lines (both start and end cursors are at start of line). In that case, a new line is added above selection with opening block delimiter, and another line is added after selection with closing block delimiter. This is the case where I was expecting the new Does that make sense? Let me know if you want to take that on or not -- I'll review code either way. |
Oh, I think we had a bit different things in mind. |
src/editor/EditorCommandHandlers.js
Outdated
function _firstNotWs(doc, lineNum) { | ||
var text = doc.getLine(lineNum); | ||
if (text === null || text === undefined) { | ||
return null; |
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.
The return value from this function is not validated -- it gets used directly as a char position. Seems like it would be more consistent with CodeMirror APIs to return -1
here (but my CM API knowledge is rusty...).
@ficristo Done with review. Looks good except for maybe 1 change. |
I seems to remember I hit a case where the API could return null, but I don't remeber which... |
@redmunds could you take a final look (and eventually merge)? |
LGTM. Merging. |
Thank you. |
…mment command
Fixes #13169
I created a new
comments
preference with an indent option with the idea of deprecate theindentLineComment
preference. Is there a way to deprecate a preference?I used a new object with the idea to add also a
padding
option in the future (like the CodeMirror addon), but maybe is better to simply create a newindentBlockComment
preference without deprecate anything.Any thought?