1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Bug 327311 - Typing 'Enter' in a multi-line comment might copy too much from the previous line

This commit is contained in:
Anton Leherbauer 2010-10-13 09:23:47 +00:00
parent f37588d11e
commit efe641d53a
2 changed files with 18 additions and 5 deletions

View file

@ -523,6 +523,15 @@ public class CAutoIndentTest extends AbstractAutoEditTest {
assertEquals("if (i > 0)\n {\n \n }", tester.fDoc.get()); 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() { private void assertNoError() {
if (!fStatusLog.isEmpty()) { if (!fStatusLog.isEmpty()) {
fail(fStatusLog.get(0).toString()); fail(fStatusLog.get(0).toString());

View file

@ -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
* <code>document</code>. The prefix greedily matches the following regex * <code>document</code>. The prefix greedily matches the following regex
* pattern: <code>\w*\*\w*</code>, that is, any number of whitespace * pattern: <code>\s*\*\S*\s*</code>, that is, any number of whitespace
* characters, followed by an asterisk ('*'), followed by any number of * 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 <code>line</code> refers * @param document the document to which <code>line</code> refers
* @param line the line from which to extract the prefix range * @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); int indentEnd= findEndOfWhiteSpaceAt(document, lineOffset, lineEnd);
if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') { if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') {
indentEnd++; indentEnd++;
while (indentEnd < lineEnd && document.getChar(indentEnd) != ' ') while (indentEnd < lineEnd && !isWhitespace(document.getChar(indentEnd)))
indentEnd++; indentEnd++;
while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ') while (indentEnd < lineEnd && isWhitespace(document.getChar(indentEnd)))
indentEnd++; indentEnd++;
} }
return new Region(lineOffset, indentEnd - lineOffset); 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 * Returns whether the text ends with one of the specified IDocument object's
* legal line delimiters. * legal line delimiters.