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

Using [url=...] breaks get_character_paragraph and get_character_line #66736

Open
nerdbeard opened this issue Oct 2, 2022 · 6 comments
Open

Comments

@nerdbeard
Copy link

Godot version

4.0.beta2

System information

Linux

Issue description

RichTextLabel fails to account for the characters taken up by the URL (I think) when [url=...] tags are used. This causes get_character_paragraph and get_character_line to return incorrect values when several long URLs are used.

Steps to reproduce

Please see https://github.com/nerdbeard/RichTextLabel-offset/blob/main/anchor.gd for a minimal example.

Minimal reproduction project

https://github.com/nerdbeard/RichTextLabel-offset

@nerdbeard
Copy link
Author

nerdbeard commented Oct 2, 2022

A comment in RichTextLabel::get_total_character_count() says:

// Note: Do not use line buffer "char_count", it includes only visible characters.

This appears to be exactly what get_character_line() and get_character_paragraph() do, they use char_count and char_offset, which only include visible characters. I think they need to be rewritten to use item->text.length() to calculate their own offsets.

I don't understand whether this would have other consequences but I'm going to try and code it and see what happens.

@nerdbeard
Copy link
Author

Maybe I need to teach RichTextLabel::append_text() to push some kind of null to represent the invisible characters

@bruvzg
Copy link
Member

bruvzg commented Oct 2, 2022

This is how it is supposed to work. get_character_line() and get_character_paragraph() count only text characters, tags are not counted (this is true for all tags, not just url).

@bruvzg
Copy link
Member

bruvzg commented Oct 2, 2022

I guess getting line/paragraph for the position in the BBCode source is useful to have, so we should add an option to do so (an extra argument for the get_character_* or a new set or functions).

@nerdbeard
Copy link
Author

Thanks, @bruvzg! Is how it's supposed to work documented anywhere?

My use case is that I want to scroll to the position of a string in the text. I only know the offset into the text I submitted to the control (which likely has BBCode in it) and I don't see that I have access to the offsets into the rendered text. I'm not sure how scroll_to_line and scroll_to_paragraph are meant to be used in conjunction with the source text, but I think I'm doing things the most obvious way.

The Line private struct of RichTextLabel has members char_offset and char_count. Could I add char_raw_offset and char_raw_count?

@nerdbeard
Copy link
Author

Calculating the required address in GDScript was a lot easier than changing the engine for me obviously but if there's any desire for this feature I'd be interested in working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants