Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve appearance of external links in built-in docs #99480

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
const Ref<Font> doc_code_font = p_owner_node->get_theme_font(SNAME("doc_source"), EditorStringName(EditorFonts));
const Ref<Font> doc_kbd_font = p_owner_node->get_theme_font(SNAME("doc_keyboard"), EditorStringName(EditorFonts));

const int doc_font_size = p_owner_node->get_theme_font_size(SNAME("doc_size"), EditorStringName(EditorFonts));
const int doc_code_font_size = p_owner_node->get_theme_font_size(SNAME("doc_source_size"), EditorStringName(EditorFonts));
const int doc_kbd_font_size = p_owner_node->get_theme_font_size(SNAME("doc_keyboard_size"), EditorStringName(EditorFonts));

Expand Down Expand Up @@ -2515,7 +2516,14 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C

tag_stack.pop_front();
pos = brk_end + 1;
if (tag != "/img") {
if (tag == "/img") {
// Nothing to do.
} else if (tag == "/url") {
p_rt->pop(); // meta
p_rt->pop(); // color
p_rt->add_text(" ");
p_rt->add_image(p_owner_node->get_editor_theme_icon(SNAME("ExternalLink")), 0, doc_font_size, link_color);
} else {
p_rt->pop();
}
} else if (tag.begins_with("method ") || tag.begins_with("constructor ") || tag.begins_with("operator ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ") || tag.begins_with("constant ") || tag.begins_with("annotation ") || tag.begins_with("theme_item ")) {
Expand Down Expand Up @@ -2783,19 +2791,20 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
} else if (tag == "rb") {
p_rt->add_text("]");
pos = brk_end + 1;
} else if (tag == "url") {
int end = bbcode.find_char('[', brk_end);
if (end == -1) {
end = bbcode.length();
} else if (tag == "url" || tag.begins_with("url=")) {
String url;
if (tag.begins_with("url=")) {
url = tag.substr(4);
} else {
int end = bbcode.find_char('[', brk_end);
if (end == -1) {
end = bbcode.length();
}
url = bbcode.substr(brk_end + 1, end - brk_end - 1);
}
String url = bbcode.substr(brk_end + 1, end - brk_end - 1);
p_rt->push_meta(url);

pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag.begins_with("url=")) {
String url = tag.substr(4);
p_rt->push_meta(url);
p_rt->push_color(link_color);
p_rt->push_meta(url, RichTextLabel::META_UNDERLINE_ON_HOVER, url + "\n\n" + TTR("Click to open in browser."));

pos = brk_end + 1;
tag_stack.push_front("url");
Expand Down