Utils: make column of convertPosition 0-based to merge it into Position

Change-Id: I239b3cb33b8ad59ac4097c919155ab5ca7d57b8e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
David Schulz
2023-05-10 09:37:25 +02:00
parent f7d46f48f8
commit 9bb126c0d6
23 changed files with 66 additions and 60 deletions

View File

@@ -147,18 +147,17 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
int line = 0;
int column = 0;
convertPosition(cursor.position(), &line, &column);
const int positionInBlock = column - 1;
const QString block = cursor.block().text();
// check if the current position is commented out
const int hashPos = block.indexOf(QLatin1Char('#'));
if (hashPos >= 0 && hashPos < positionInBlock)
if (hashPos >= 0 && hashPos < column)
return processLinkCallback(link);
// find the beginning of a filename
QString buffer;
int beginPos = positionInBlock - 1;
int beginPos = column - 1;
while (beginPos >= 0) {
if (isValidFileNameChar(block, beginPos)) {
buffer.prepend(block.at(beginPos));
@@ -169,7 +168,7 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
}
// find the end of a filename
int endPos = positionInBlock;
int endPos = column;
while (endPos < block.count()) {
if (isValidFileNameChar(block, endPos)) {
buffer.append(block.at(endPos));
@@ -199,8 +198,8 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
return processLinkCallback(link);
}
link.targetFilePath = Utils::FilePath::fromString(fileName);
link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1;
link.linkTextEnd = cursor.position() - positionInBlock + endPos;
link.linkTextStart = cursor.position() - column + beginPos + 1;
link.linkTextEnd = cursor.position() - column + endPos;
}
processLinkCallback(link);
}