diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java index 96d11fb1b90..edaef1b7b94 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java @@ -523,6 +523,15 @@ public class CAutoIndentTest extends AbstractAutoEditTest { assertEquals("if (i > 0)\n {\n \n }", tester.fDoc.get()); } + public void testCopyCommentPrefix_Bug327311() throws Exception { + AutoEditTester tester = createAutoEditTester(); + tester.type("/*\n"); //$NON-NLS-1$ + assertEquals(" * ", tester.getLine()); + tester.backspace(); // delete space + tester.type("\tDemonstrate\n"); //$NON-NLS-1$ + assertEquals(" *\t", tester.getLine()); + } + private void assertNoError() { if (!fStatusLog.isEmpty()) { fail(fStatusLog.get(0).toString()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java index 959eea84270..82ce3ae92f3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java @@ -376,11 +376,11 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg } /** - * Returns the range of the java-doc prefix on the given line in + * Returns the range of the comment prefix on the given line in * document. The prefix greedily matches the following regex - * pattern: \w*\*\w*, that is, any number of whitespace + * pattern: \s*\*\S*\s*, that is, any number of whitespace * characters, followed by an asterisk ('*'), followed by any number of - * whitespace characters. + * non-whitespace characters, followed by any number of whitespace characters. * * @param document the document to which line refers * @param line the line from which to extract the prefix range @@ -394,14 +394,18 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg int indentEnd= findEndOfWhiteSpaceAt(document, lineOffset, lineEnd); if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') { indentEnd++; - while (indentEnd < lineEnd && document.getChar(indentEnd) != ' ') + while (indentEnd < lineEnd && !isWhitespace(document.getChar(indentEnd))) indentEnd++; - while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ') + while (indentEnd < lineEnd && isWhitespace(document.getChar(indentEnd))) indentEnd++; } return new Region(lineOffset, indentEnd - lineOffset); } + private static boolean isWhitespace(char ch) { + return ch == ' ' || ch == '\t'; + } + /** * Returns whether the text ends with one of the specified IDocument object's * legal line delimiters.