fix(textarea): scroll to position when style changes (#9407)

This commit is contained in:
André Costa
2026-01-19 13:05:07 +01:00
committed by GitHub
parent 9f3918f66e
commit e23b7bebf4
4 changed files with 13 additions and 3 deletions
+5 -3
View File
@@ -7,10 +7,11 @@
* INCLUDES
*********************/
#include "lv_textarea_private.h"
#include "../label/lv_label_private.h"
#include "../../core/lv_obj_class_private.h"
#if LV_USE_TEXTAREA != 0
#include "../label/lv_label_private.h"
#include "../../core/lv_obj_class_private.h"
#include "../../core/lv_group.h"
#include "../../core/lv_refr.h"
#include "../../indev/lv_indev.h"
@@ -988,7 +989,7 @@ static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e)
else if(code == LV_EVENT_DRAW_POST) {
draw_cursor(e);
}
else if(code == LV_EVENT_SIZE_CHANGED) {
else if(code == LV_EVENT_SIZE_CHANGED || code == LV_EVENT_STYLE_CHANGED) {
lv_textarea_t * ta = (lv_textarea_t *)obj;
lv_textarea_scroll_to_cusor_pos(obj, ta->cursor.pos);
}
@@ -1474,6 +1475,7 @@ static void lv_textarea_scroll_to_cusor_pos(lv_obj_t * obj, int32_t pos)
lv_textarea_t * ta = (lv_textarea_t *)obj;
lv_point_t cur_pos;
lv_obj_update_layout(ta->label);
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
lv_label_get_letter_pos(ta->label, pos, &cur_pos);
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -83,6 +83,14 @@ void test_textarea_should_scroll_to_the_end(void)
TEST_ASSERT(lv_textarea_get_one_line(textarea));
}
void test_textarea_should_not_scroll_if_text_is_fully_visible(void)
{
lv_textarea_set_text(textarea, "Type here...");
lv_obj_set_width(textarea, 100);
lv_obj_center(textarea);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/textarea_1.png");
}
void test_textarea_should_update_placeholder_text(void)
{
const char * new_placeholder = "LVGL Rocks!!!!!";