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

Method seekHunk

plugins/patchreview/patchreview.cpp:68–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68void PatchReviewPlugin::seekHunk( bool forwards, const QUrl& fileName ) {
69 try {
70 qCDebug(PLUGIN_PATCHREVIEW) << forwards << fileName << fileName.isEmpty();
71 if ( !m_modelList )
72 throw "no model";
73
74 for ( int a = 0; a < m_modelList->modelCount(); ++a ) {
75 const auto* const model = m_modelList->modelAt(a);
76 if ( !model || !model->differences() )
77 continue;
78
79 QUrl file = urlForFileModel( model );
80
81 if ( !fileName.isEmpty() && fileName != file )
82 continue;
83
84 IDocument* doc = ICore::self()->documentController()->documentForUrl( file );
85
86 if ( doc && m_highlighters.contains( doc->url() ) && m_highlighters[doc->url()] ) {
87 if ( doc->textDocument() ) {
88 const QList<KTextEditor::MovingRange*> ranges = m_highlighters[doc->url()]->ranges();
89
90 KTextEditor::View * v = doc->activeTextView();
91 if ( v ) {
92 int bestLine = -1;
93 KTextEditor::Cursor c = v->cursorPosition();
94 for (auto* range : ranges) {
95 const int line = range->start().line();
96
97 if ( forwards ) {
98 if ( line > c.line() && ( bestLine == -1 || line < bestLine ) )
99 bestLine = line;
100 } else {
101 if ( line < c.line() && ( bestLine == -1 || line > bestLine ) )
102 bestLine = line;
103 }
104 }
105 if ( bestLine != -1 ) {
106 v->setCursorPosition( KTextEditor::Cursor( bestLine, 0 ) );
107 return;
108 } else if(fileName.isEmpty()) {
109 int next = qBound(0, forwards ? a+1 : a-1, m_modelList->modelCount()-1);
110 if (next < maximumFilesToOpenDirectly) {
111 ICore::self()->documentController()->openDocument(urlForFileModel(m_modelList->modelAt(next)));
112 }
113 }
114 }
115 }
116 }
117 }
118 } catch ( const QString & str ) {
119 qCDebug(PLUGIN_PATCHREVIEW) << "seekHunk():" << str;
120 } catch ( const char * str ) {
121 qCDebug(PLUGIN_PATCHREVIEW) << "seekHunk():" << str;
122 }
123 qCDebug(PLUGIN_PATCHREVIEW) << "no matching hunk found";
124}
125

Callers 3

nextHunkMethod · 0.80
prevHunkMethod · 0.80
openMethod · 0.80

Calls 14

documentForUrlMethod · 0.80
documentControllerMethod · 0.80
rangesMethod · 0.80
CursorClass · 0.70
isEmptyMethod · 0.45
containsMethod · 0.45
urlMethod · 0.45
textDocumentMethod · 0.45
activeTextViewMethod · 0.45
cursorPositionMethod · 0.45
lineMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected