Fix mixed markup sending.
This commit is contained in:
parent
53b3b24867
commit
cf7a779689
|
@ -2284,10 +2284,22 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
|
||||||
auto result = TextWithTags();
|
auto result = TextWithTags();
|
||||||
result.text.reserve(originalText.size());
|
result.text.reserve(originalText.size());
|
||||||
result.tags.reserve(originalTags.size() + _lastMarkdownTags.size());
|
result.tags.reserve(originalTags.size() + _lastMarkdownTags.size());
|
||||||
auto from = 0;
|
|
||||||
auto removed = 0;
|
auto removed = 0;
|
||||||
auto originalTag = originalTags.begin();
|
auto originalTag = originalTags.begin();
|
||||||
const auto originalTagsEnd = originalTags.end();
|
const auto originalTagsEnd = originalTags.end();
|
||||||
|
const auto addOriginalTagsUpTill = [&](int offset) {
|
||||||
|
while (originalTag != originalTagsEnd
|
||||||
|
&& originalTag->offset + originalTag->length <= offset) {
|
||||||
|
result.tags.push_back(*originalTag++);
|
||||||
|
result.tags.back().offset -= removed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
auto from = 0;
|
||||||
|
const auto addOriginalTextUpTill = [&](int offset) {
|
||||||
|
if (offset > from) {
|
||||||
|
result.text.append(originalText.midRef(from, offset - from));
|
||||||
|
}
|
||||||
|
};
|
||||||
auto link = links.begin();
|
auto link = links.begin();
|
||||||
const auto linksEnd = links.end();
|
const auto linksEnd = links.end();
|
||||||
for (const auto &tag : _lastMarkdownTags) {
|
for (const auto &tag : _lastMarkdownTags) {
|
||||||
|
@ -2299,11 +2311,7 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
|
||||||
if (entityLength <= 0) {
|
if (entityLength <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while (originalTag != originalTagsEnd
|
addOriginalTagsUpTill(tag.start);
|
||||||
&& originalTag->offset + originalTag->length <= tag.start) {
|
|
||||||
result.tags.push_back(*originalTag++);
|
|
||||||
result.tags.back().offset -= removed;
|
|
||||||
}
|
|
||||||
if (originalTag != originalTagsEnd
|
if (originalTag != originalTagsEnd
|
||||||
&& originalTag->offset < tag.start + tag.length) {
|
&& originalTag->offset < tag.start + tag.length) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -2318,9 +2326,7 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
|
||||||
|| link->offset() < tag.start)) {
|
|| link->offset() < tag.start)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tag.start > from) {
|
addOriginalTextUpTill(tag.start);
|
||||||
result.text.append(originalText.midRef(from, tag.start - from));
|
|
||||||
}
|
|
||||||
result.tags.push_back(TextWithTags::Tag{
|
result.tags.push_back(TextWithTags::Tag{
|
||||||
int(result.text.size()),
|
int(result.text.size()),
|
||||||
entityLength,
|
entityLength,
|
||||||
|
@ -2330,9 +2336,8 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
|
||||||
from = tag.start + tag.length;
|
from = tag.start + tag.length;
|
||||||
removed += 2 * tagLength;
|
removed += 2 * tagLength;
|
||||||
}
|
}
|
||||||
if (originalText.size() > from) {
|
addOriginalTagsUpTill(originalText.size());
|
||||||
result.text.append(originalText.midRef(from));
|
addOriginalTextUpTill(originalText.size());
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue