From ef275977d877e19fee54632361a82ea360f3622a Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Sun, 30 May 2010 16:35:25 +0400 Subject: [PATCH] Restored for consistency: "if line comment prefix is followed by a single space, uncomment line action deletes that space (PY-980)"" This reverts commit 0de5b6dd19224ee3d3992e92a04a9df24aa4066f. --- .../generation/CommentByLineCommentHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java index a3f2b6d1f104..96f723a291d6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java @@ -464,8 +464,15 @@ public class CommentByLineCommentHandler implements CodeInsightActionHandler { boolean commented = CharArrayUtil.regionMatches(chars, startOffset, prefix) || (skipNewLine = prefix.endsWith(" ") && CharArrayUtil.regionMatches(chars, startOffset, prefix.trim() + "\n")); assert commented; - int position = 0;//text.indexOf(prefix); - myDocument.deleteString(position + startOffset , position + startOffset + (skipNewLine? prefix.trim().length():prefix.length())); + + int charsToDelete = skipNewLine ? prefix.trim().length() : prefix.length(); + int theEnd = endOffset > 0 ? endOffset : chars.length(); + // if there's exactly one space after line comment prefix and before the text that follows in the same line, delete the space too + if (startOffset + charsToDelete < theEnd-2 && chars.charAt(startOffset+charsToDelete) == ' ' && + chars.charAt(startOffset+charsToDelete+1) != ' ') { + charsToDelete++; + } + myDocument.deleteString(startOffset, startOffset + charsToDelete); return; } String text = myDocument.getCharsSequence().subSequence(startOffset, endOffset).toString();