MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / highlightDifferences

Method highlightDifferences

widgets/RefactorWidget.cpp:291–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291void RefactorWidget::highlightDifferences()
292{
293 if (m_cachedDiffList.isEmpty()) {
294 return;
295 }
296
297 QList<Utils::Diff> leftDiffs;
298 QList<Utils::Diff> rightDiffs;
299 Utils::Differ::splitDiffList(m_cachedDiffList, &leftDiffs, &rightDiffs);
300
301 int contextBeforeOffset = m_contextBefore.isEmpty() ? 0 : (m_contextBefore.length() + 1);
302
303 QColor normalTextColor = Utils::creatorColor(Utils::Theme::TextColorNormal);
304
305 QTextCursor leftCursor(m_leftDocument->document());
306 QTextCharFormat removedFormat;
307 QColor removedBg = Utils::creatorColor(Utils::Theme::TextColorError);
308 removedBg.setAlpha(30);
309 removedFormat.setBackground(removedBg);
310 removedFormat.setForeground(normalTextColor);
311
312 int leftPos = 0;
313 for (const auto &diff : leftDiffs) {
314 if (diff.command == Utils::Diff::Delete) {
315 leftCursor.setPosition(contextBeforeOffset + leftPos);
316 leftCursor.setPosition(contextBeforeOffset + leftPos + diff.text.length(), QTextCursor::KeepAnchor);
317 leftCursor.setCharFormat(removedFormat);
318 }
319 if (diff.command != Utils::Diff::Insert) {
320 leftPos += diff.text.length();
321 }
322 }
323
324 QTextCursor rightCursor(m_rightDocument->document());
325 QTextCharFormat addedFormat;
326 QColor addedBg = Utils::creatorColor(Utils::Theme::IconsRunColor);
327 addedBg.setAlpha(60);
328 addedFormat.setBackground(addedBg);
329 addedFormat.setForeground(normalTextColor);
330
331 int rightPos = 0;
332 for (const auto &diff : rightDiffs) {
333 if (diff.command == Utils::Diff::Insert) {
334 rightCursor.setPosition(contextBeforeOffset + rightPos);
335 rightCursor.setPosition(contextBeforeOffset + rightPos + diff.text.length(), QTextCursor::KeepAnchor);
336 rightCursor.setCharFormat(addedFormat);
337 }
338 if (diff.command != Utils::Diff::Delete) {
339 rightPos += diff.text.length();
340 }
341 }
342}
343
344void RefactorWidget::dimContextLines(const QString &contextBefore, const QString &contextAfter)
345{

Callers

nothing calls this directly

Calls 3

documentMethod · 0.80
setPositionMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected