diff --git a/ui/text/text.cpp b/ui/text/text.cpp index 5b21a63..f53e648 100644 --- a/ui/text/text.cpp +++ b/ui/text/text.cpp @@ -1225,8 +1225,8 @@ bool String::hasNotEmojiAndSpaces() const { return _hasNotEmojiAndSpaces; } -const base::flat_map &String::modifications() const { - static const auto kEmpty = base::flat_map(); +const std::vector &String::modifications() const { + static const auto kEmpty = std::vector(); return _extended ? _extended->modifications : kEmpty; } diff --git a/ui/text/text.h b/ui/text/text.h index 4792391..00c63a8 100644 --- a/ui/text/text.h +++ b/ui/text/text.h @@ -83,9 +83,10 @@ struct SpoilerData; struct ParagraphDetails; struct ExtendedData; -struct Deltas { - uint16 added = 0; - uint16 removed = 0; +struct Modification { + int position = 0; + uint16 skipped = 0; + bool added = false; }; struct StateRequest { @@ -341,7 +342,7 @@ public: [[nodiscard]] OnlyCustomEmoji toOnlyCustomEmoji() const; [[nodiscard]] bool hasNotEmojiAndSpaces() const; - [[nodiscard]] const base::flat_map &modifications() const; + [[nodiscard]] const std::vector &modifications() const; [[nodiscard]] const style::TextStyle *style() const { return _st; diff --git a/ui/text/text_block.cpp b/ui/text/text_block.cpp index 478c69e..43c5288 100644 --- a/ui/text/text_block.cpp +++ b/ui/text/text_block.cpp @@ -388,9 +388,7 @@ style::font WithFlags( || (fontFlags & FontSemibold)) { result = result->semibold(); } - if ((flags & TextBlockFlag::Italic) - || (fontFlags & FontItalic) - || (flags & TextBlockFlag::Blockquote)) { + if ((flags & TextBlockFlag::Italic) || (fontFlags & FontItalic)) { result = result->italic(); } if ((flags & TextBlockFlag::Underline) || (fontFlags & FontUnderline)) { diff --git a/ui/text/text_extended_data.h b/ui/text/text_extended_data.h index a4151ea..f8901ca 100644 --- a/ui/text/text_extended_data.h +++ b/ui/text/text_extended_data.h @@ -12,8 +12,7 @@ namespace Ui::Text { -struct Deltas; - +struct Modification; class String; class SpoilerClickHandler final : public ClickHandler { @@ -59,7 +58,7 @@ struct ExtendedData { std::vector links; std::vector paragraphs; std::unique_ptr spoiler; - base::flat_map modifications; + std::vector modifications; }; } // namespace Ui::Text diff --git a/ui/text/text_parser.cpp b/ui/text/text_parser.cpp index bd66466..080b138 100644 --- a/ui/text/text_parser.cpp +++ b/ui/text/text_parser.cpp @@ -603,11 +603,25 @@ bool Parser::isLinkEntity(const EntityInText &entity) const { } void Parser::updateModifications(int index, int delta) { - auto &deltas = _t->ensureExtended()->modifications[index]; - if (delta > 0) { - deltas.added += delta; + auto &modifications = _t->ensureExtended()->modifications; + auto i = end(modifications); + while (i != begin(modifications) && (--i)->position >= index) { + if (i->position < index) { + break; + } else if (delta > 0) { + ++i->position; + } else if (i->position == index) { + break; + } + } + if (i != end(modifications) && i->position == index) { + ++i->skipped; } else { - deltas.removed -= delta; + modifications.insert(i, { + .position = index, + .skipped = uint16(delta < 0 ? 1 : 0), + .added = (delta > 0), + }); } } diff --git a/ui/text/text_renderer.cpp b/ui/text/text_renderer.cpp index 9d4eb0c..896ca0c 100644 --- a/ui/text/text_renderer.cpp +++ b/ui/text/text_renderer.cpp @@ -433,6 +433,18 @@ void Renderer::fillParagraphBg(int paddingBottom) { .skipTop = !isTop, .skipBottom = !isBottom, }); + + if (isTop && cache->withHeader) { + const auto font = _t->_st->font->monospace(); + const auto topleft = rect.topLeft(); + const auto position = topleft + _t->_st->blockHeaderPosition; + const auto baseline = position + QPoint(0, font->ascent); + _p->setFont(font); + _p->setPen(_palette->monoFg->p); + _p->drawText(baseline, _paragraph->language.isEmpty() + ? u"code"_q + : _paragraph->language); + } } _blockLineTop = _y + _lineHeight + paddingBottom; } @@ -2094,7 +2106,7 @@ void Renderer::applyBlockProperties(const AbstractBlock *block) { _currentPen = &_originalPen; _currentPenSelected = &_originalPenSelected; } - } else if (isMono || (flags & TextBlockFlag::Blockquote)) { + } else if (isMono) { _currentPen = &_palette->monoFg->p; _currentPenSelected = &_palette->selectMonoFg->p; } else if (block->linkIndex()) {