Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/codegen/documentchangeset.cpp
Show First 20 Lines • Show All 373 Lines • ▼ Show 20 Line(s) | |||||
374 | { | 374 | { | ||
375 | 375 | | |||
376 | ISourceFormatter* formatter = nullptr; | 376 | ISourceFormatter* formatter = nullptr; | ||
377 | if(ICore::self()) { | 377 | if(ICore::self()) { | ||
378 | formatter = ICore::self()->sourceFormatterController()->formatterForUrl(file.toUrl()); | 378 | formatter = ICore::self()->sourceFormatterController()->formatterForUrl(file.toUrl()); | ||
379 | } | 379 | } | ||
380 | 380 | | |||
381 | //Create the actual new modified file | 381 | //Create the actual new modified file | ||
382 | QStringList textLines = repr->text().split('\n'); | 382 | QStringList textLines = repr->text().split(QLatin1Char('\n')); | ||
383 | 383 | | |||
384 | QUrl url = file.toUrl(); | 384 | QUrl url = file.toUrl(); | ||
385 | 385 | | |||
386 | QMimeType mime = QMimeDatabase().mimeTypeForUrl(url); | 386 | QMimeType mime = QMimeDatabase().mimeTypeForUrl(url); | ||
387 | QVector<int> removedLines; | 387 | QVector<int> removedLines; | ||
388 | 388 | | |||
389 | for(int pos = sortedChanges.size()-1; pos >= 0; --pos) { | 389 | for(int pos = sortedChanges.size()-1; pos >= 0; --pos) { | ||
390 | DocumentChange& change(*sortedChanges[pos]); | 390 | DocumentChange& change(*sortedChanges[pos]); | ||
Show All 10 Lines | 394 | { | |||
401 | if(formatter && (formatPolicy == DocumentChangeSet::AutoFormatChanges | 401 | if(formatter && (formatPolicy == DocumentChangeSet::AutoFormatChanges | ||
402 | || formatPolicy == DocumentChangeSet::AutoFormatChangesKeepIndentation)) | 402 | || formatPolicy == DocumentChangeSet::AutoFormatChangesKeepIndentation)) | ||
403 | { | 403 | { | ||
404 | QString oldNewText = change.m_newText; | 404 | QString oldNewText = change.m_newText; | ||
405 | change.m_newText = formatter->formatSource(change.m_newText, url, mime, leftContext, rightContext); | 405 | change.m_newText = formatter->formatSource(change.m_newText, url, mime, leftContext, rightContext); | ||
406 | 406 | | |||
407 | if(formatPolicy == DocumentChangeSet::AutoFormatChangesKeepIndentation) { | 407 | if(formatPolicy == DocumentChangeSet::AutoFormatChangesKeepIndentation) { | ||
408 | // Reproduce the previous indentation | 408 | // Reproduce the previous indentation | ||
409 | QStringList oldLines = oldNewText.split('\n'); | 409 | QStringList oldLines = oldNewText.split(QLatin1Char('\n')); | ||
410 | QStringList newLines = change.m_newText.split('\n'); | 410 | QStringList newLines = change.m_newText.split(QLatin1Char('\n')); | ||
411 | 411 | | |||
412 | if(oldLines.size() == newLines.size()) { | 412 | if(oldLines.size() == newLines.size()) { | ||
413 | for(int line = 0; line < newLines.size(); ++line) { | 413 | for(int line = 0; line < newLines.size(); ++line) { | ||
414 | // Keep the previous indentation | 414 | // Keep the previous indentation | ||
415 | QString oldIndentation; | 415 | QString oldIndentation; | ||
416 | for (int a = 0; a < oldLines[line].size(); ++a) { | 416 | for (int a = 0; a < oldLines[line].size(); ++a) { | ||
417 | if (oldLines[line][a].isSpace()) { | 417 | if (oldLines[line][a].isSpace()) { | ||
418 | oldIndentation.append(oldLines[line][a]); | 418 | oldIndentation.append(oldLines[line][a]); | ||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |