refactor: merge adjecent words into one TextElement (#5847)

This commit is contained in:
nerix
2025-01-22 23:25:00 +01:00
committed by GitHub
parent ea02a42162
commit 0a3cc1deed
42 changed files with 289 additions and 2719 deletions
+43
View File
@@ -674,6 +674,49 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
}
}
const MessageColor &TextElement::color() const noexcept
{
return this->color_;
}
FontStyle TextElement::fontStyle() const noexcept
{
return this->style_;
}
void TextElement::appendText(QStringView text)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
for (auto word : text.split(' ')) // creates a QList
#else
for (auto word : text.tokenize(u' '))
#endif
{
this->words_.append(word.toString());
}
}
void TextElement::appendText(const QString &text)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
this->appendText(QStringView{text});
#else
qsizetype firstSpace = text.indexOf(u' ');
if (firstSpace == -1)
{
// reuse (ref) `text`
this->words_.emplace_back(text);
return;
}
this->words_.emplace_back(text.sliced(0, firstSpace));
for (auto word : QStringView{text}.sliced(firstSpace + 1).tokenize(u' '))
{
this->words_.emplace_back(word.toString());
}
#endif
}
QJsonObject TextElement::toJson() const
{
auto base = MessageElement::toJson();