Improve blockquote / pre layout.
This commit is contained in:
parent
7ed87d049f
commit
6e7c4c1c4d
6 changed files with 41 additions and 17 deletions
|
|
@ -1225,8 +1225,8 @@ bool String::hasNotEmojiAndSpaces() const {
|
|||
return _hasNotEmojiAndSpaces;
|
||||
}
|
||||
|
||||
const base::flat_map<int, Deltas> &String::modifications() const {
|
||||
static const auto kEmpty = base::flat_map<int, Deltas>();
|
||||
const std::vector<Modification> &String::modifications() const {
|
||||
static const auto kEmpty = std::vector<Modification>();
|
||||
return _extended ? _extended->modifications : kEmpty;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<int, Deltas> &modifications() const;
|
||||
[[nodiscard]] const std::vector<Modification> &modifications() const;
|
||||
|
||||
[[nodiscard]] const style::TextStyle *style() const {
|
||||
return _st;
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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<ClickHandlerPtr> links;
|
||||
std::vector<ParagraphDetails> paragraphs;
|
||||
std::unique_ptr<SpoilerData> spoiler;
|
||||
base::flat_map<int, Deltas> modifications;
|
||||
std::vector<Modification> modifications;
|
||||
};
|
||||
|
||||
} // namespace Ui::Text
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue