textarea: add insert handler functions
This commit is contained in:
@@ -60,6 +60,7 @@ static void pwd_char_hider(lv_obj_t * ta);
|
||||
static bool char_is_accepted(lv_obj_t * ta, uint32_t c);
|
||||
static void refr_cursor_area(lv_obj_t * ta);
|
||||
static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_indev_t * click_source);
|
||||
static lv_res_t insert_handler(lv_obj_t * ta, const char * txt);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -243,18 +244,9 @@ void lv_textarea_add_char(lv_obj_t * ta, uint32_t c)
|
||||
if(c != 0) while(*letter_buf == 0) ++letter_buf;
|
||||
#endif
|
||||
|
||||
ta_insert_replace = NULL;
|
||||
lv_res_t res = insert_handler(ta, letter_buf);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
if(ta_insert_replace) {
|
||||
if(ta_insert_replace[0] == '\0') return; /*Drop this text*/
|
||||
|
||||
/*Add the replaced text directly it's different from the original*/
|
||||
if(strcmp(ta_insert_replace, letter_buf)) {
|
||||
lv_textarea_add_text(ta, ta_insert_replace);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(ext->one_line && (c == '\n' || c == '\r')) {
|
||||
LV_LOG_INFO("Text area: line break ignored in one-line mode");
|
||||
return;
|
||||
@@ -268,7 +260,6 @@ void lv_textarea_add_char(lv_obj_t * ta, uint32_t c)
|
||||
return;
|
||||
}
|
||||
|
||||
lv_event_send(ta, LV_EVENT_INSERT, letter_buf);
|
||||
|
||||
/*If a new line was added it shouldn't show edge flash effect*/
|
||||
bool edge_flash_en = lv_textarea_get_edge_flash(ta);
|
||||
@@ -335,17 +326,6 @@ void lv_textarea_add_text(lv_obj_t * ta, const char * txt)
|
||||
|
||||
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
||||
|
||||
ta_insert_replace = NULL;
|
||||
if(ta_insert_replace) {
|
||||
if(ta_insert_replace[0] == '\0') return; /*Drop this text*/
|
||||
|
||||
/*Add the replaced text directly it's different from the original*/
|
||||
if(strcmp(ta_insert_replace, txt)) {
|
||||
lv_textarea_add_text(ta, ta_insert_replace);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
||||
|
||||
/*Add the character one-by-one if not all characters are accepted or there is character limit.*/
|
||||
@@ -358,7 +338,9 @@ void lv_textarea_add_text(lv_obj_t * ta, const char * txt)
|
||||
return;
|
||||
}
|
||||
|
||||
lv_event_send(ta, LV_EVENT_INSERT, txt);
|
||||
lv_res_t res = insert_handler(ta, txt);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
/*If a new line was added it shouldn't show edge flash effect*/
|
||||
bool edge_flash_en = lv_textarea_get_edge_flash(ta);
|
||||
lv_textarea_set_edge_flash(ta, false);
|
||||
@@ -421,18 +403,10 @@ void lv_textarea_del_char(lv_obj_t * ta)
|
||||
|
||||
if(cur_pos == 0) return;
|
||||
|
||||
ta_insert_replace = NULL;
|
||||
char del_buf[2] = {LV_KEY_DEL, '\0'};
|
||||
lv_event_send(ta, LV_EVENT_INSERT, del_buf);
|
||||
if(ta_insert_replace) {
|
||||
if(ta_insert_replace[0] == '\0') return; /*Drop this text*/
|
||||
|
||||
/*Add the replaced text directly it's different from the original*/
|
||||
if(strcmp(ta_insert_replace, del_buf)) {
|
||||
lv_textarea_add_text(ta, ta_insert_replace);
|
||||
return;
|
||||
}
|
||||
}
|
||||
lv_res_t res = insert_handler(ta, del_buf);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
char * label_txt = lv_label_get_text(ext->label);
|
||||
|
||||
@@ -1917,4 +1891,21 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_
|
||||
#endif
|
||||
}
|
||||
|
||||
static lv_res_t insert_handler(lv_obj_t * ta, const char * txt)
|
||||
{
|
||||
ta_insert_replace = NULL;
|
||||
lv_event_send(ta, LV_EVENT_INSERT, txt);
|
||||
if(ta_insert_replace) {
|
||||
if(ta_insert_replace[0] == '\0') return LV_RES_INV; /*Drop this text*/
|
||||
|
||||
/*Add the replaced text directly it's different from the original*/
|
||||
if(strcmp(ta_insert_replace, txt)) {
|
||||
lv_textarea_add_text(ta, ta_insert_replace);
|
||||
return LV_RES_INV;
|
||||
}
|
||||
}
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user