Skip to content

Commit 5f04527

Browse files
committed
core: Fix double caret rendering in justified text
The condition visible_selection.start() >= *start && visible_selection.end() <= *end was inaccurate, because the end of the selection is exclusive. That caused the condition to be true for two adjacent boxes. For instance: box 1: from 0 to 6, "hello " box 2: from 6 to 11, "world" The caret was rendered for both boxes when it was at position 6. When applying a correct condition (i.e. treating the end as exclusive) there is a problem with rendering the caret at the very end of the text, because the condition will not be triggered for any box (position 11 in the example above). That is why a condition specific to this case is added, i.e. *end == text_len When the box is the last box in the text, we are forcing the caret to be rendered.
1 parent eec5e90 commit 5f04527

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/src/display_object/edit_text.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,11 @@ impl<'gc> EditText<'gc> {
902902

903903
let caret = if let LayoutContent::Text { start, end, .. } = &lbox.content() {
904904
if let Some(visible_selection) = visible_selection {
905+
let text_len = edit_text.text_spans.text().len();
905906
if visible_selection.is_caret()
906907
&& !edit_text.flags.contains(EditTextFlag::READ_ONLY)
907908
&& visible_selection.start() >= *start
908-
&& visible_selection.end() <= *end
909+
&& (visible_selection.end() < *end || *end == text_len)
909910
&& !visible_selection.blinks_now()
910911
{
911912
Some(visible_selection.start() - start)

0 commit comments

Comments
 (0)