Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2121 from TomMalbran/tom/fix-issue-2118
Browse files Browse the repository at this point in the history
Fix: If first line in selection is a line comment, Block Comment does nothing
  • Loading branch information
redmunds committed Dec 5, 2012
2 parents d5074de + e3eb887 commit c93c170
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,24 @@ define(function (require, exports, module) {

// Check if we should just do a line uncomment (if all lines in the selection are commented).
if (slashComment && (ctx.token.string.match(lineExp) || endCtx.token.string.match(lineExp))) {
var ctxPos = {line: ctx.pos.line, ch: ctx.pos.ch};
var endCtxIndex = editor.indexFromPos({line: endCtx.pos.line, ch: endCtx.token.start + endCtx.token.string.length});

// Find if we aren't actually inside a block-comment
result = true;
while (result && ctx.token.string.match(lineExp)) {
result = TokenUtils.moveSkippingWhitespace(TokenUtils.movePrevToken, ctx);
}

// If we aren't in a block-comment.
if (!result || ctx.token.className !== "comment" || ctx.token.string.match(suffixExp)) {
// We aren't in an block-comment. Find if all the lines are line-commented.
if (!_containsUncommented(editor, sel.start.line, sel.end.line)) {
// If the selection includes all the line-comments, do a block-comment
if (editor.posWithinRange(ctxPos, sel.start, sel.end) &&
(!endCtx.token.string.match(lineExp) || editor.indexFromPos(sel.end) >= endCtxIndex)) {
canComment = true;

// Find if all the lines are line-commented.
} else if (!_containsUncommented(editor, sel.start.line, sel.end.line)) {
lineUncomment = true;

// If can't uncomment then do nothing, since it would create an invalid comment.
Expand Down

0 comments on commit c93c170

Please sign in to comment.