Commit 3f879c0c authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

Git: Use correct line numbers in limited range blame

Change-Id: I12f6fc77b532e5b01f2da6c1c1ff847445447c70
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 3845c833
......@@ -670,6 +670,7 @@ void GitPlugin::blameFile()
QTC_ASSERT(state.hasFile(), return);
const int lineNumber = VcsBaseEditor::lineNumberOfCurrentEditor(state.currentFile());
QStringList extraOptions;
int firstLine = -1;
if (BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor()) {
QTextCursor cursor = textEditor->textCursor();
if (cursor.hasSelection()) {
......@@ -677,15 +678,25 @@ void GitPlugin::blameFile()
int selectionStart = cursor.selectionStart();
int selectionEnd = cursor.selectionEnd();
cursor.setPosition(selectionStart);
argument += QString::number(cursor.blockNumber() + 1) + ',';
const int startBlock = cursor.blockNumber();
firstLine = startBlock + 1;
if (auto widget = qobject_cast<VcsBaseEditorWidget *>(textEditor->widget())) {
const int previousFirstLine = widget->firstLineNumber();
if (previousFirstLine > 0)
firstLine = previousFirstLine;
}
argument += QString::number(firstLine) + ',';
cursor.setPosition(selectionEnd);
cursor.blockNumber();
argument += QString::number(cursor.blockNumber() + 1);
const int endBlock = cursor.blockNumber();
argument += QString::number(endBlock + firstLine - startBlock);
extraOptions << argument;
}
}
m_gitClient->annotate(state.currentFileTopLevel(), state.relativeCurrentFile(), QString(),
lineNumber, extraOptions);
VcsBaseEditorWidget *editor = m_gitClient->annotate(
state.currentFileTopLevel(), state.relativeCurrentFile(), QString(),
lineNumber, extraOptions);
if (firstLine > 0)
editor->setFirstLineNumber(firstLine);
}
void GitPlugin::logProject()
......
......@@ -561,6 +561,7 @@ public:
QRegExp m_logEntryPattern;
QList<int> m_entrySections; // line number where this section starts
int m_cursorLine = -1;
int m_firstLineNumber = -1;
QString m_annotateRevisionTextFormat;
QString m_annotatePreviousRevisionTextFormat;
QString m_copyRevisionTextFormat;
......@@ -681,6 +682,37 @@ QString VcsBaseEditorWidget::fileNameForLine(int line) const
return source();
}
int VcsBaseEditorWidget::firstLineNumber() const
{
return d->m_firstLineNumber;
}
void VcsBaseEditorWidget::setFirstLineNumber(int firstLineNumber)
{
d->m_firstLineNumber = firstLineNumber;
}
QString VcsBaseEditorWidget::lineNumber(int blockNumber) const
{
if (d->m_firstLineNumber > 0)
return QString::number(d->m_firstLineNumber + blockNumber);
return TextEditorWidget::lineNumber(blockNumber);
}
int VcsBaseEditorWidget::lineNumberDigits() const
{
if (d->m_firstLineNumber <= 0)
return TextEditorWidget::lineNumberDigits();
int digits = 2;
int max = qMax(1, d->m_firstLineNumber + blockCount());
while (max >= 100) {
max /= 10;
++digits;
}
return digits;
}
void VcsBaseEditorWidget::setDescribeSlot(QObject *describeReceiver, const char *describeSlot)
{
d->m_describeReceiver = describeReceiver;
......
......@@ -154,6 +154,9 @@ protected:
virtual bool supportChangeLinks() const;
virtual QString fileNameForLine(int line) const;
QString lineNumber(int blockNumber) const override;
int lineNumberDigits() const override;
public:
void finalizeInitialization() override;
// FIXME: Consolidate these into finalizeInitialization
......@@ -199,6 +202,9 @@ public:
QString workingDirectory() const;
void setWorkingDirectory(const QString &wd);
int firstLineNumber() const;
void setFirstLineNumber(int firstLineNumber);
bool isModified() const;
EditorContentType contentType() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment