forked from qt-creator/qt-creator
Utils: Make column of LineColumn consistently 0-based
Change-Id: I4ab153d1c55653936efbcdc13ac04463185930e0 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
bool isValid() const
|
bool isValid() const
|
||||||
{
|
{
|
||||||
return line >= 0 && column >= 0;
|
return line > 0 && column >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator==(LineColumn first, LineColumn second)
|
friend bool operator==(LineColumn first, LineColumn second)
|
||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
static LineColumn extractFromFileName(QStringView fileName, int &postfixPos);
|
static LineColumn extractFromFileName(QStringView fileName, int &postfixPos);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int line = -1;
|
int line = 0;
|
||||||
int column = -1;
|
int column = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ OptionalLineColumn convertPosition(const QTextDocument *document, int pos)
|
|||||||
QTextBlock block = document->findBlock(pos);
|
QTextBlock block = document->findBlock(pos);
|
||||||
|
|
||||||
if (block.isValid())
|
if (block.isValid())
|
||||||
optional.emplace(block.blockNumber() + 1, pos - block.position() + 1);
|
optional.emplace(block.blockNumber() + 1, pos - block.position());
|
||||||
|
|
||||||
return optional;
|
return optional;
|
||||||
}
|
}
|
||||||
@@ -180,8 +180,7 @@ LineColumn utf16LineColumn(const QByteArray &utf8Buffer, int utf8Offset)
|
|||||||
: 0;
|
: 0;
|
||||||
lineColumn.column = QString::fromUtf8(
|
lineColumn.column = QString::fromUtf8(
|
||||||
utf8Buffer.mid(startOfLineOffset, utf8Offset - startOfLineOffset))
|
utf8Buffer.mid(startOfLineOffset, utf8Offset - startOfLineOffset))
|
||||||
.length()
|
.length();
|
||||||
+ 1;
|
|
||||||
return lineColumn;
|
return lineColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ void CppEditorOutline::updateIndexNow()
|
|||||||
|
|
||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
m_editorWidget->convertPosition(m_editorWidget->position(), &line, &column);
|
m_editorWidget->convertPosition(m_editorWidget->position(), &line, &column);
|
||||||
QModelIndex comboIndex = m_model->indexForPosition(line, column);
|
QModelIndex comboIndex = m_model->indexForPosition(line, column - 1);
|
||||||
|
|
||||||
if (comboIndex.isValid()) {
|
if (comboIndex.isValid()) {
|
||||||
QSignalBlocker blocker(m_combo);
|
QSignalBlocker blocker(m_combo);
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ void CppOutlineWidget::updateIndexNow()
|
|||||||
|
|
||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
m_editor->convertPosition(m_editor->position(), &line, &column);
|
m_editor->convertPosition(m_editor->position(), &line, &column);
|
||||||
QModelIndex index = m_model->indexForPosition(line, column);
|
QModelIndex index = m_model->indexForPosition(line, column - 1);
|
||||||
|
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
m_blockCursorSync = true;
|
m_blockCursorSync = true;
|
||||||
@@ -194,8 +194,7 @@ void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex)
|
|||||||
Core::EditorManager::cutForwardNavigationHistory();
|
Core::EditorManager::cutForwardNavigationHistory();
|
||||||
Core::EditorManager::addCurrentPositionToNavigationHistory();
|
Core::EditorManager::addCurrentPositionToNavigationHistory();
|
||||||
|
|
||||||
// line has to be 1 based, column 0 based!
|
m_editor->gotoLine(lineColumn.line, lineColumn.column, true, true);
|
||||||
m_editor->gotoLine(lineColumn.line, lineColumn.column - 1, true, true);
|
|
||||||
m_blockCursorSync = false;
|
m_blockCursorSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ Utils::LineColumn OutlineModel::lineColumnFromIndex(const QModelIndex &sourceInd
|
|||||||
if (!symbol)
|
if (!symbol)
|
||||||
return lineColumn;
|
return lineColumn;
|
||||||
lineColumn.line = symbol->line();
|
lineColumn.line = symbol->line();
|
||||||
lineColumn.column = symbol->column();
|
lineColumn.column = symbol->column() - 1;
|
||||||
return lineColumn;
|
return lineColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
using Range = std::pair<Utils::LineColumn, Utils::LineColumn>;
|
using Range = std::pair<Utils::LineColumn, Utils::LineColumn>;
|
||||||
Range rangeFromIndex(const QModelIndex &sourceIndex) const;
|
Range rangeFromIndex(const QModelIndex &sourceIndex) const;
|
||||||
|
|
||||||
|
// line is 1-based and column is 0-based
|
||||||
QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = {}) const;
|
QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = {}) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1095,7 +1095,7 @@ void tst_filepath::linkFromString_data()
|
|||||||
QTest::addColumn<int>("column");
|
QTest::addColumn<int>("column");
|
||||||
|
|
||||||
QTest::newRow("no-line-no-column")
|
QTest::newRow("no-line-no-column")
|
||||||
<< QString("someFile.txt") << FilePath("someFile.txt") << -1 << -1;
|
<< QString("someFile.txt") << FilePath("someFile.txt") << 0 << -1;
|
||||||
QTest::newRow(": at end") << QString::fromLatin1("someFile.txt:") << FilePath("someFile.txt")
|
QTest::newRow(": at end") << QString::fromLatin1("someFile.txt:") << FilePath("someFile.txt")
|
||||||
<< 0 << -1;
|
<< 0 << -1;
|
||||||
QTest::newRow("+ at end") << QString::fromLatin1("someFile.txt+") << FilePath("someFile.txt")
|
QTest::newRow("+ at end") << QString::fromLatin1("someFile.txt+") << FilePath("someFile.txt")
|
||||||
@@ -1121,7 +1121,7 @@ void tst_filepath::linkFromString_data()
|
|||||||
QTest::newRow("+line-+column") << QString::fromLatin1("/some/path/file.txt+142+33")
|
QTest::newRow("+line-+column") << QString::fromLatin1("/some/path/file.txt+142+33")
|
||||||
<< FilePath("/some/path/file.txt") << 142 << 32;
|
<< FilePath("/some/path/file.txt") << 142 << 32;
|
||||||
QTest::newRow("( at end") << QString::fromLatin1("/some/path/file.txt(")
|
QTest::newRow("( at end") << QString::fromLatin1("/some/path/file.txt(")
|
||||||
<< FilePath("/some/path/file.txt") << -1 << -1;
|
<< FilePath("/some/path/file.txt") << 0 << -1;
|
||||||
QTest::newRow("(42 at end") << QString::fromLatin1("/some/path/file.txt(42")
|
QTest::newRow("(42 at end") << QString::fromLatin1("/some/path/file.txt(42")
|
||||||
<< FilePath("/some/path/file.txt") << 42 << -1;
|
<< FilePath("/some/path/file.txt") << 42 << -1;
|
||||||
QTest::newRow("(42) at end") << QString::fromLatin1("/some/path/file.txt(42)")
|
QTest::newRow("(42) at end") << QString::fromLatin1("/some/path/file.txt(42)")
|
||||||
|
|||||||
Reference in New Issue
Block a user