@@ -760,10 +760,11 @@ void TextEdit::_notification(int p_what) {
760760 const Ref<TextParagraph> &ac_buf = text.get_line_data (i);
761761 const Vector<RID> &text_aes = text.get_accessibility_elements (i);
762762 int first_indent_line = 0 ;
763+ float indent_ofs = 0.0 ;
763764 if (text.is_indent_wrapped_lines ()) {
764765 _get_wrapped_indent_level (i, first_indent_line);
766+ indent_ofs = MIN (text.get_indent_offset (i, rtl), wrap_at_column * 0.6 );
765767 }
766- float indent_ofs = MIN (text.get_indent_offset (i, rtl), wrap_at_column * 0.6 );
767768 for (int j = 0 ; j < text_aes.size (); j++) {
768769 float text_off_x = 0.0 ;
769770 float text_off_y = 0.0 ;
@@ -1345,10 +1346,11 @@ void TextEdit::_notification(int p_what) {
13451346 int line_wrap_amount = draw_placeholder ? placeholder_wrapped_rows.size () - 1 : get_line_wrap_count (line);
13461347
13471348 int first_indent_line = 0 ;
1349+ float indent_ofs = 0.0 ;
13481350 if (text.is_indent_wrapped_lines ()) {
13491351 _get_wrapped_indent_level (line, first_indent_line);
1352+ indent_ofs = MIN (text.get_indent_offset (line, rtl), wrap_at_column * 0.6 );
13501353 }
1351- float indent_ofs = MIN (text.get_indent_offset (line, rtl), wrap_at_column * 0.6 );
13521354 for (int line_wrap_index = 0 ; line_wrap_index <= line_wrap_amount; line_wrap_index++) {
13531355 if (line_wrap_index != 0 ) {
13541356 i++;
@@ -2382,11 +2384,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
23822384 if (inline_object_click_handler.is_valid ()) {
23832385 int xmargin_beg = Math::ceil (theme_cache.style_normal ->get_margin (SIDE_LEFT)) + gutters_width + gutter_padding;
23842386 int wrap_i = get_line_wrap_index_at_column (pos.y , pos.x );
2385- int first_indent_line = 0 ;
2386- if (text.is_indent_wrapped_lines ()) {
2387- _get_wrapped_indent_level (pos.y , first_indent_line);
2388- }
2389- float wrap_indent = wrap_i > first_indent_line ? MIN (text.get_indent_offset (pos.y , is_layout_rtl ()), wrap_at_column * 0.6 ) : 0.0 ;
2387+ const float wrap_indent = _get_wrap_indent_offset (pos.y , wrap_i, is_layout_rtl ());
23902388
23912389 Ref<TextParagraph> ldata = text.get_line_data (line);
23922390 for (const Variant &inline_key : ldata->get_line_objects (wrap_i)) {
@@ -3610,11 +3608,7 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
36103608 Point2i pos = get_line_column_at_pos (p_pos);
36113609 int xmargin_beg = Math::ceil (theme_cache.style_normal ->get_margin (SIDE_LEFT)) + gutters_width + gutter_padding;
36123610 int wrap_i = get_line_wrap_index_at_column (pos.y , pos.x );
3613- int first_indent_line = 0 ;
3614- if (text.is_indent_wrapped_lines ()) {
3615- _get_wrapped_indent_level (pos.y , first_indent_line);
3616- }
3617- float wrap_indent = wrap_i > first_indent_line ? MIN (text.get_indent_offset (pos.y , is_layout_rtl ()), wrap_at_column * 0.6 ) : 0.0 ;
3611+ const float wrap_indent = _get_wrap_indent_offset (pos.y , wrap_i, is_layout_rtl ());
36183612
36193613 Ref<TextParagraph> ldata = text.get_line_data (pos.y );
36203614 for (Variant k : ldata->get_line_objects (wrap_i)) {
@@ -4111,6 +4105,18 @@ int TextEdit::_get_wrapped_indent_level(int p_line, int &r_first_wrap) const {
41114105 return tab_count * text.get_tab_size () + whitespace_count;
41124106}
41134107
4108+ float TextEdit::_get_wrap_indent_offset (int p_line, int p_wrap_index, bool p_rtl) const {
4109+ if (!text.is_indent_wrapped_lines ()) {
4110+ return 0 ;
4111+ }
4112+ int first_indent_line = 0 ;
4113+ _get_wrapped_indent_level (p_line, first_indent_line);
4114+ if (p_wrap_index > first_indent_line) {
4115+ return MIN (text.get_indent_offset (p_line, p_rtl), wrap_at_column * 0.6 );
4116+ }
4117+ return 0 ;
4118+ }
4119+
41144120int TextEdit::get_indent_level (int p_line) const {
41154121 ERR_FAIL_INDEX_V (p_line, text.size (), 0 );
41164122
@@ -4999,11 +5005,8 @@ Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_clamp_line
49995005 RID text_rid = text.get_line_data (row)->get_line_rid (wrap_index);
50005006
50015007 bool rtl = is_layout_rtl ();
5002- int first_indent_line = 0 ;
5003- if (text.is_indent_wrapped_lines ()) {
5004- _get_wrapped_indent_level (row, first_indent_line);
5005- }
5006- float wrap_indent = wrap_index > first_indent_line ? MIN (text.get_indent_offset (row, rtl), wrap_at_column * 0.6 ) : 0.0 ;
5008+ const float wrap_indent = _get_wrap_indent_offset (row, wrap_index, rtl);
5009+
50075010 if (rtl) {
50085011 colx = TS->shaped_text_get_size (text_rid).x - colx + wrap_indent;
50095012 } else {
@@ -5056,9 +5059,11 @@ Rect2i TextEdit::get_rect_at_line_column(int p_line, int p_column) const {
50565059 return Rect2i (-1 , -1 , 0 , 0 );
50575060 }
50585061
5062+ const float wrap_indent = _get_wrap_indent_offset (p_line, wrap_index, is_layout_rtl ());
5063+
50595064 Point2i pos, size;
50605065 pos.y = cache_entry.y_offset + get_line_height () * wrap_index;
5061- pos.x = get_total_gutter_width () + Math::ceil (theme_cache.style_normal ->get_margin (SIDE_LEFT)) - get_h_scroll ();
5066+ pos.x = get_total_gutter_width () + Math::ceil (theme_cache.style_normal ->get_margin (SIDE_LEFT)) + wrap_indent - get_h_scroll ();
50625067
50635068 RID text_rid = text.get_line_data (p_line)->get_line_rid (wrap_index);
50645069 Vector2 col_bounds = TS->shaped_text_get_grapheme_bounds (text_rid, p_column);
@@ -8168,11 +8173,8 @@ int TextEdit::_get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) con
81688173 p_wrap_index = MIN (p_wrap_index, text.get_line_data (p_line)->get_line_count () - 1 );
81698174
81708175 RID text_rid = text.get_line_data (p_line)->get_line_rid (p_wrap_index);
8171- int first_indent_line = 0 ;
8172- if (text.is_indent_wrapped_lines ()) {
8173- _get_wrapped_indent_level (p_line, first_indent_line);
8174- }
8175- float wrap_indent = p_wrap_index > first_indent_line ? MIN (text.get_indent_offset (p_line, is_layout_rtl ()), wrap_at_column * 0.6 ) : 0.0 ;
8176+ const float wrap_indent = _get_wrap_indent_offset (p_line, p_wrap_index, is_layout_rtl ());
8177+
81768178 if (is_layout_rtl ()) {
81778179 p_px = TS->shaped_text_get_size (text_rid).x - p_px + wrap_indent;
81788180 } else {
@@ -8231,22 +8233,19 @@ void TextEdit::_toggle_draw_caret() {
82318233int TextEdit::_get_column_x_offset_for_line (int p_char, int p_line, int p_column) const {
82328234 ERR_FAIL_INDEX_V (p_line, text.size (), 0 );
82338235
8234- int row = 0 ;
8235- Vector<Vector2i> rows2 = text.get_line_wrap_ranges (p_line);
8236- for (int i = 0 ; i < rows2 .size (); i++) {
8237- if ((p_char >= rows2 [i].x ) && (p_char < rows2 [i].y || (i == rows2 .size () - 1 && p_char == rows2 [i].y ))) {
8238- row = i;
8236+ int wrap_index = 0 ;
8237+ Vector<Vector2i> wrap_ranges = text.get_line_wrap_ranges (p_line);
8238+ for (int i = 0 ; i < wrap_ranges .size (); i++) {
8239+ if ((p_char >= wrap_ranges [i].x ) && (p_char < wrap_ranges [i].y || (i == wrap_ranges .size () - 1 && p_char == wrap_ranges [i].y ))) {
8240+ wrap_index = i;
82398241 break ;
82408242 }
82418243 }
82428244
8243- RID text_rid = text.get_line_data (p_line)->get_line_rid (row );
8245+ RID text_rid = text.get_line_data (p_line)->get_line_rid (wrap_index );
82448246 bool rtl = is_layout_rtl ();
8245- int first_indent_line = 0 ;
8246- if (text.is_indent_wrapped_lines ()) {
8247- _get_wrapped_indent_level (p_line, first_indent_line);
8248- }
8249- float wrap_indent = row > first_indent_line ? MIN (text.get_indent_offset (p_line, rtl), wrap_at_column * 0.6 ) : 0.0 ;
8247+ const float wrap_indent = _get_wrap_indent_offset (p_line, wrap_index, rtl);
8248+
82508249 CaretInfo ts_caret = TS->shaped_text_get_carets (text_rid, p_column);
82518250 if ((ts_caret.l_caret != Rect2 () && (ts_caret.l_dir == TextServer::DIRECTION_AUTO || ts_caret.l_dir == (TextServer::Direction)input_direction)) || (ts_caret.t_caret == Rect2 ())) {
82528251 return ts_caret.l_caret .position .x + (rtl ? -wrap_indent : wrap_indent);
0 commit comments