Skip to content

Commit 46aff5c

Browse files
committed
Merge pull request #94848 from kitbdev/fix-placeholder-fit-content
Fix TextEdit placeholder fit content height
2 parents 5793d79 + b6c054e commit 46aff5c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

scene/gui/text_edit.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ void TextEdit::_notification(int p_what) {
764764
}
765765
}
766766

767-
bool draw_placeholder = text.size() == 1 && text[0].is_empty() && ime_text.is_empty();
767+
bool draw_placeholder = _using_placeholder();
768768

769769
// Get the highlighted words.
770770
String highlighted_text = get_selected_text(0);
@@ -2849,6 +2849,10 @@ void TextEdit::_update_placeholder() {
28492849
}
28502850
}
28512851

2852+
bool TextEdit::_using_placeholder() const {
2853+
return text.size() == 1 && text[0].is_empty() && ime_text.is_empty();
2854+
}
2855+
28522856
void TextEdit::_update_theme_item_cache() {
28532857
Control::_update_theme_item_cache();
28542858

@@ -7840,10 +7844,10 @@ void TextEdit::_update_scrollbars() {
78407844
h_scroll->set_begin(Point2(0, size.height - hmin.height));
78417845
h_scroll->set_end(Point2(size.width - vmin.width, size.height));
78427846

7843-
bool draw_placeholder = text.size() == 1 && text[0].length() == 0;
7847+
bool draw_placeholder = _using_placeholder();
78447848

78457849
int visible_rows = get_visible_line_count();
7846-
int total_rows = draw_placeholder ? placeholder_wraped_rows.size() - 1 : get_total_visible_line_count();
7850+
int total_rows = draw_placeholder ? placeholder_wraped_rows.size() : get_total_visible_line_count();
78477851
if (scroll_past_end_of_file_enabled && !fit_content_height) {
78487852
total_rows += visible_rows - 1;
78497853
}
@@ -7921,7 +7925,7 @@ void TextEdit::_scroll_moved(double p_to_val) {
79217925
}
79227926
if (v_scroll->is_visible_in_tree()) {
79237927
// Set line ofs and wrap ofs.
7924-
bool draw_placeholder = text.size() == 1 && text[0].length() == 0;
7928+
bool draw_placeholder = _using_placeholder();
79257929

79267930
int v_scroll_i = floor(get_v_scroll());
79277931
int sc = 0;

scene/gui/text_edit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ class TextEdit : public Control {
297297
Vector<String> placeholder_wraped_rows;
298298

299299
void _update_placeholder();
300+
bool _using_placeholder() const;
300301

301302
/* Initialize to opposite first, so we get past the early-out in set_editable. */
302303
bool editable = false;

0 commit comments

Comments
 (0)