MCPcopy Create free account
hub / github.com/KDE/kdevelop / gotoSrcLine

Method gotoSrcLine

plugins/git/diffviewsctrl.cpp:392–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392void DiffViewsCtrl::gotoSrcLine()
393{
394 auto vData = activeView();
395 if (!vData.isValid() || !vData.actView)
396 return;
397
398 auto* docCtrl = ICore::self()->documentController();
399 auto diffLn = vData.actView->cursorPosition().line();
400 auto diffCol = vData.actView->cursorPosition().column();
401 VcsDiff diff;
402 diff.setDiff(vData.ktDoc->text());
403
404 // Find the closest line in the diff which has a corresponding
405 // source line
406 auto last_line = vData.ktDoc->documentEnd().line();
407 int delta = 0;
408 while(diffLn - delta >= 1 || diffLn + delta < last_line) {
409 auto src = diff.diffLineToTarget(diffLn-delta);
410 if ( src.line < 0 ) src = diff.diffLineToTarget(diffLn+delta);
411 if ( src.line >= 0 ) {
412 auto path = KDevelop::Path(vData.project->path(), src.path);
413 if (auto* srcDoc = docCtrl->openDocument(path.toUrl())) {
414 srcDoc->setCursorPosition(KTextEditor::Cursor(src.line, diffCol-1));
415 docCtrl->activateDocument(srcDoc);
416 }
417 return;
418 }
419 delta += 1;
420 }
421}
422
423#include "moc_diffviewsctrl.cpp"

Callers

nothing calls this directly

Calls 15

documentControllerMethod · 0.80
diffLineToTargetMethod · 0.80
activateDocumentMethod · 0.80
PathClass · 0.50
CursorClass · 0.50
isValidMethod · 0.45
lineMethod · 0.45
cursorPositionMethod · 0.45
columnMethod · 0.45
setDiffMethod · 0.45
textMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected