edit select all when get focus

This commit is contained in:
xianjimli 2019-09-27 05:56:47 +08:00
parent f5cf240a84
commit f01a3d070e
3 changed files with 23 additions and 0 deletions

View File

@ -1103,6 +1103,12 @@ ret_t text_edit_set_select(text_edit_t* text_edit, uint32_t start, uint32_t end)
return RET_OK;
}
ret_t text_edit_select_all(text_edit_t* text_edit) {
return_value_if_fail(text_edit != NULL, RET_BAD_PARAMS);
return text_edit_set_select(text_edit, 0, text_edit->widget->text.size);
}
ret_t text_edit_unselect(text_edit_t* text_edit) {
DECL_IMPL(text_edit);
return_value_if_fail(text_edit != NULL, RET_BAD_PARAMS);

View File

@ -152,6 +152,15 @@ ret_t text_edit_key_down(text_edit_t* text_edit, key_event_t* evt);
*/
ret_t text_edit_set_select(text_edit_t* text_edit, uint32_t start, uint32_t end);
/**
* @method text_edit_select_all
*
* @param {text_edit_t*} text_edit text_edit对象
*
* @return {ret_t} RET_OK表示成功
*/
ret_t text_edit_select_all(text_edit_t* text_edit);
/**
* @method text_edit_unselect
*

View File

@ -454,6 +454,13 @@ static ret_t edit_on_key_down(widget_t* widget, key_event_t* e) {
return RET_STOP;
}
static ret_t edit_select_all_async(const idle_info_t* info) {
edit_t* edit = EDIT(info->ctx);
text_edit_select_all(edit->model);
return RET_REMOVE;
}
ret_t edit_on_event(widget_t* widget, event_t* e) {
ret_t ret = RET_OK;
uint32_t type = e->type;
@ -534,6 +541,7 @@ ret_t edit_on_event(widget_t* widget, event_t* e) {
if (widget->target == NULL) {
edit_request_input_method(widget);
idle_add(edit_select_all_async, edit);
}
break;
}