diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 073ffd2fd8a..40fef9d0597 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -606,7 +606,7 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) { Ref font = get_font("font"); if (font != NULL) { for (int i = selection.begin; i < selection.end; i++) - cached_width -= font->get_char_size(text[i]).width; + cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width; } text.erase(selection.begin, selected); @@ -1066,11 +1066,7 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { int char_w = 0; if (font != NULL) { - if (is_secret()) { - char_w = font->get_char_size(secret_character[0]).width; - } else { - char_w = font->get_char_size(text[ofs]).width; - } + char_w = font->get_char_size(pass ? secret_character[0] : text[ofs]).width; } pixel_ofs += char_w; @@ -1122,7 +1118,7 @@ int LineEdit::get_cursor_pixel_pos() { while (ofs < cursor_pos) { if (font != NULL) { - pixel_ofs += font->get_char_size(text[ofs]).width; + pixel_ofs += font->get_char_size(pass ? secret_character[0] : text[ofs]).width; } ofs++; } @@ -1181,7 +1177,7 @@ void LineEdit::delete_char() { Ref font = get_font("font"); if (font != NULL) { - cached_width -= font->get_char_size(text[cursor_pos - 1]).width; + cached_width -= font->get_char_size(pass ? secret_character[0] : text[cursor_pos - 1]).width; } text.erase(cursor_pos - 1, 1); @@ -1201,7 +1197,7 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) { Ref font = get_font("font"); if (font != NULL) { for (int i = p_from_column; i < p_to_column; i++) - cached_width -= font->get_char_size(text[i]).width; + cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width; } } else { cached_width = 0; @@ -1325,7 +1321,11 @@ void LineEdit::set_cursor_position(int p_pos) { // Do not do this, because if the cursor is at the end, its just fine that it takes no space. // accum_width = font->get_char_size(' ').width; } else { - accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do. + if (pass) { + accum_width += font->get_char_size(secret_character[0], i + 1 < text.length() ? secret_character[0] : 0).width; + } else { + accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do. + } } if (accum_width > window_width) break;