| 453 | } |
| 454 | |
| 455 | void PatchHighlighter::textInserted(KTextEditor::Document* doc, const KTextEditor::Cursor& cursor, const QString& text) { |
| 456 | Q_ASSERT(cursor.isValid()); |
| 457 | if ( m_applying ) { // Do not interfere with patch application |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | int startLine = cursor.line(); |
| 462 | int endColumn = cursor.column() + text.length(); |
| 463 | |
| 464 | qCDebug(PLUGIN_PATCHREVIEW) << "insertion range" << |
| 465 | KTextEditor::Range(cursor, KTextEditor::Cursor(startLine, endColumn)); |
| 466 | qCDebug(PLUGIN_PATCHREVIEW) << "inserted text" << text; |
| 467 | |
| 468 | QStringList removedLines; |
| 469 | QStringList insertedLines; |
| 470 | if (startLine > 0) { |
| 471 | const QString above = doc->line(--startLine) + QLatin1Char('\n'); |
| 472 | removedLines << above; |
| 473 | insertedLines << above; |
| 474 | } |
| 475 | |
| 476 | const QString changed = doc->line(cursor.line()) + QLatin1Char('\n'); |
| 477 | const QStringView changedView = changed; |
| 478 | Q_ASSERT(endColumn <= changed.size()); |
| 479 | removedLines << changedView.first(cursor.column()) + changedView.sliced(endColumn); |
| 480 | insertedLines << changed; |
| 481 | |
| 482 | if (doc->documentRange().end().line() > cursor.line()) { |
| 483 | const QString below = doc->line(cursor.line() + 1) + QLatin1Char('\n'); |
| 484 | removedLines << below; |
| 485 | insertedLines << below; |
| 486 | } |
| 487 | |
| 488 | performContentChange(doc, removedLines, insertedLines, startLine + 1); |
| 489 | } |
| 490 | |
| 491 | void PatchHighlighter::newlineInserted(KTextEditor::Document* doc, const KTextEditor::Cursor& cursor) |
| 492 | { |