From 22c1a88a790c99bdd444ba843cc706f1e5735bc1 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 5 Mar 2020 03:36:30 +0300 Subject: [PATCH] Add support for back to top anchor links. GitOrigin-RevId: 4d1c15db95eca645e90df08e19b8cefd569ee158 --- td/generate/scheme/td_api.tl | 2 +- td/telegram/WebPageBlock.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b2596654..5f7aa546 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -849,7 +849,7 @@ richTextReference text:RichText reference_text:RichText url:string = RichText; //@description An anchor @name Anchor name richTextAnchor name:string = RichText; -//@description A link to an anchor on the same web page @text The link text @name The anchor name @url An HTTP URL, opening the anchor +//@description A link to an anchor on the same web page @text The link text @name The anchor name. If the name is empty, the link should bring back to top @url An HTTP URL, opening the anchor richTextAnchorLink text:RichText name:string url:string = RichText; //@description A concatenation of rich texts @texts Texts diff --git a/td/telegram/WebPageBlock.cpp b/td/telegram/WebPageBlock.cpp index bc207153..79ddb2f4 100644 --- a/td/telegram/WebPageBlock.cpp +++ b/td/telegram/WebPageBlock.cpp @@ -118,7 +118,7 @@ class RichText { return make_tl_object(texts[0].get_rich_text_object(context)); case RichText::Type::Url: if (!context->base_url_.empty() && begins_with(content, context->base_url_) && - content.size() > context->base_url_.size() + 1 && content[context->base_url_.size()] == '#') { + content[context->base_url_.size()] == '#') { if (context->is_first_pass_) { context->has_anchor_urls_ = true; } else { @@ -2399,6 +2399,7 @@ vector> get_page_block_objects( } context.is_first_pass_ = false; + context.anchors_.emplace(Slice(), nullptr); // back to top return get_page_block_objects(page_blocks, &context); }