forked from qt-creator/qt-creator
Core: remove impractical offset member of text position
It is just accessed when getting the length of multiline ranges and in that case we can pass the string that range is used on to calculate the real length. Change-Id: I3fe95ac0cd4b05a08924a5285a75ebc5eed2423b Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -40,11 +40,9 @@ class TextPosition
|
||||
public:
|
||||
TextPosition() = default;
|
||||
TextPosition(int line, int column) : line(line), column(column) {}
|
||||
TextPosition(int line, int column, int offset) : line(line), column(column), offset(offset) {}
|
||||
|
||||
int line = -1; // (0 or -1 for no line number)
|
||||
int column = -1; // 0-based starting position for a mark (-1 for no mark)
|
||||
int offset = -1;
|
||||
|
||||
bool operator<(const TextPosition &other)
|
||||
{ return line < other.line || (line == other.line && column < other.column); }
|
||||
@@ -56,28 +54,26 @@ public:
|
||||
TextRange() = default;
|
||||
TextRange(TextPosition begin, TextPosition end) : begin(begin), end(end) {}
|
||||
|
||||
QString mid(const QString &text) const
|
||||
{
|
||||
if (begin.line == end.line)
|
||||
return text.mid(begin.column, end.column - begin.column);
|
||||
QString mid(const QString &text) const { return text.mid(begin.column, length(text)); }
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
int endLineOffsetDifference() const
|
||||
{
|
||||
if (Utils::HostOsInfo::isWindowsHost())
|
||||
return begin.line - end.line;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int length() const
|
||||
int length(const QString &text) const
|
||||
{
|
||||
if (begin.line == end.line)
|
||||
return end.column - begin.column;
|
||||
|
||||
return end.offset - begin.offset - endLineOffsetDifference();
|
||||
const int lineCount = end.line - begin.line;
|
||||
int index = text.indexOf(QChar::LineFeed);
|
||||
int currentLine = 1;
|
||||
while (index > 0 && currentLine < lineCount) {
|
||||
++index;
|
||||
index = text.indexOf(QChar::LineFeed, index);
|
||||
++currentLine;
|
||||
}
|
||||
|
||||
if (index < 0)
|
||||
return 0;
|
||||
|
||||
return index - begin.column + end.column;
|
||||
}
|
||||
|
||||
TextPosition begin;
|
||||
|
@@ -276,7 +276,7 @@ QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role)
|
||||
result = row->item.mainRange.begin.column;
|
||||
break;
|
||||
case ItemDataRoles::SearchTermLengthRole:
|
||||
result = row->item.mainRange.length();
|
||||
result = row->item.mainRange.length(row->item.text);
|
||||
break;
|
||||
case ItemDataRoles::IsGeneratedRole:
|
||||
result = row->isGenerated();
|
||||
|
@@ -529,7 +529,7 @@ QStringList BaseFileFind::replaceAll(const QString &text,
|
||||
if (item.userData.canConvert<QStringList>() && !item.userData.toStringList().isEmpty()) {
|
||||
replacement = Utils::expandRegExpReplacement(text, item.userData.toStringList());
|
||||
} else if (preserveCase) {
|
||||
const QString originalText = (item.mainRange.length() == 0)
|
||||
const QString originalText = (item.mainRange.length(item.text) == 0)
|
||||
? item.text
|
||||
: item.mainRange.mid(item.text);
|
||||
replacement = Utils::matchCaseReplacement(originalText, text);
|
||||
|
@@ -34,8 +34,7 @@ inline
|
||||
bool operator==(const TextPosition first, class TextPosition second)
|
||||
{
|
||||
return first.line == second.line
|
||||
&& first.column == second.column
|
||||
&& first.offset == second.offset;
|
||||
&& first.column == second.column;
|
||||
}
|
||||
|
||||
inline
|
||||
|
Reference in New Issue
Block a user