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

Fix: If first line in selection is a line comment, Block Comment does nothing #2121

Merged
merged 2 commits into from
Dec 5, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,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