CppEditor: Fix added newlines for GenerateGetterSetter quick fix

As a nice side effect superfluous new lines - introduced by quick fixes
that are using InsertionPointLocator::methodDefinition - vanished.

Task-number: QTCREATORBUG-13872
Change-Id: Ib3df2b2acbc22449f16f4444092a57ae93d53d35
Reviewed-by: Jochen Becher <jochen_becher@gmx.de>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Lorenz Haas
2015-02-01 11:32:45 +01:00
committed by Nikolai Kosjar
parent 03212d6e49
commit 7879aa5fae
3 changed files with 29 additions and 30 deletions

View File

@@ -617,8 +617,16 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition(Symbol *declara
} else {
QTC_ASSERT(column, return result);
prefix = QLatin1String("\n\n");
int firstNonSpace = targetFile->position(line, column);
prefix = QLatin1String("\n\n");
// Only one new line if at the end of file
if (const QTextDocument *doc = targetFile->document()) {
if (firstNonSpace + 1 == doc->characterCount() /* + 1 because zero based index */
&& doc->characterAt(firstNonSpace) == QChar::ParagraphSeparator) {
prefix = QLatin1String("\n");
}
}
QChar c = targetFile->charAt(firstNonSpace);
while (c == QLatin1Char(' ') || c == QLatin1Char('\t')) {
++firstNonSpace;