Skip to content

Commit

Permalink
Improve appearance of external links in built-in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickeon committed Dec 2, 2024
1 parent d741a64 commit b22bb4d
Showing 1 changed file with 21 additions and 12 deletions.
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

0 comments on commit b22bb4d

Please sign in to comment.