| 360 | } |
| 361 | |
| 362 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override |
| 363 | { |
| 364 | auto* const document = view->document(); |
| 365 | |
| 366 | DocumentChangeSet changes; |
| 367 | KTextEditor::Cursor rangeStart = word.start(); |
| 368 | |
| 369 | // try and replace leading typed text that match the proposed implementation |
| 370 | const QString leading = document->line(word.end().line()).left(word.end().column()); |
| 371 | const QString leadingNoSpace = removeWhitespace(leading); |
| 372 | if (!leadingNoSpace.isEmpty() && (removeWhitespace(m_display).startsWith(leadingNoSpace) |
| 373 | || removeWhitespace(m_replacement).startsWith(leadingNoSpace))) { |
| 374 | const int removeSize = leading.end() - std::find_if_not(leading.begin(), leading.end(), |
| 375 | [](QChar c){ return c.isSpace(); }); |
| 376 | rangeStart = {word.end().line(), word.end().column() - removeSize}; |
| 377 | } |
| 378 | |
| 379 | DocumentChange change(IndexedString(view->document()->url()), |
| 380 | KTextEditor::Range(rangeStart, word.end()), |
| 381 | QString(), |
| 382 | m_replacement); |
| 383 | change.m_ignoreOldText = true; |
| 384 | changes.addChange(change); |
| 385 | changes.applyAllChanges(); |
| 386 | |
| 387 | // Place cursor after the opening brace |
| 388 | // arbitrarily chose 4, as it would accommodate the template and return types on their own line |
| 389 | const auto searchRange = KTextEditor::Range(rangeStart, rangeStart.line() + 4, 0); |
| 390 | const auto results = view->document()->searchText(searchRange, QStringLiteral("{")); |
| 391 | if (!results.isEmpty()) { |
| 392 | view->setCursorPosition(results.first().end()); |
| 393 | } |
| 394 | } |
| 395 | }; |
| 396 | |
| 397 | class ArgumentHintItem : public DeclarationItem |
nothing calls this directly
no test coverage detected