@@ -34,8 +34,21 @@ local function set_selection_width(self, selection_width)
3434end
3535
3636
37+ --- @param self druid.rich_input
3738local function update_text (self )
38- local left_text_part = utf8 .sub (self .input :get_text (), 0 , self .input .cursor_index )
39+ local full_text = self .input :get_text ()
40+ local visible_text = self .input .text :get_text ()
41+
42+ local is_truncated = visible_text ~= full_text
43+ local cursor_index = self .input .cursor_index
44+ if is_truncated then
45+ -- If text is truncated, we need to adjust the cursor index
46+ -- to the last visible character
47+ cursor_index = utf8.len (visible_text )
48+
49+ end
50+
51+ local left_text_part = utf8 .sub (self .input :get_text (), 0 , cursor_index )
3952 local selected_text_part = utf8 .sub (self .input :get_text (), self .input .start_index + 1 , self .input .end_index )
4053
4154 local left_part_width = self .input .text :get_text_size (left_text_part )
@@ -44,7 +57,7 @@ local function update_text(self)
4457 local pivot_text = gui .get_pivot (self .input .text .node )
4558 local pivot_offset = helper .get_pivot_offset (pivot_text )
4659
47- self .cursor_position .x = self .text_position .x - self .input .total_width * (0.5 + pivot_offset .x ) + left_part_width
60+ self .cursor_position .x = self .text_position .x - self .input .text_width * (0.5 + pivot_offset .x ) + left_part_width
4861
4962 gui .set_position (self .cursor , self .cursor_position )
5063 gui .set_scale (self .cursor , self .input .text .scale )
0 commit comments