mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 327311 - Typing 'Enter' in a multi-line comment might copy too much from the previous line
This commit is contained in:
parent
f37588d11e
commit
efe641d53a
2 changed files with 18 additions and 5 deletions
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
* 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
|
||||
* whitespace characters.
|
||||
* non-whitespace characters, followed by any number of whitespace characters.
|
||||
*
|
||||
* @param document the document to which <code>line</code> 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.
|
||||
|
|
Loading…
Add table
Reference in a new issue