Fix TextServer::shaped_text_get_grapheme_bounds() returning the bounds of the wrong grapheme #108280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #108269.
A text of "abc" produces three glyphs with start/end pairs of (0, 1), (1, 2), and (2, 3), so apparently
end
is exclusive. This means that this condition for when the correct position is reached leads to an off-by-one error:godot/servers/text_server.cpp
Line 1635 in 9b22b41
If
p_pos == 1
(we want the bounds of character index 1) andglyph[0].start == 0
andglyph[0].end == 1
, then this will already be true fori == 0
and return the position of the first glyph instead of the second.This is a rather fundamental change for something that's been like this for four years, so maybe there's quite a bit of code out there that compensates for this behavior and would produce incorrect results if we fix it? Then again, just having it return incorrect values forever doesn't feel quite right either.
Edit: Oh, wow, this change fails all the test cases. 😳 Maybe it was actually inteded that way and the better route would be to document that this function and functions that use it use 1-based indexing?
This test case clicks at the center of character 0, drags a bit past the center of character 5, and expects to then have 5 characters selected. Is that what we want? I'm confused.