diff --git a/src/base/text_edit.c b/src/base/text_edit.c index b5c24ee64..1f3d570d5 100644 --- a/src/base/text_edit.c +++ b/src/base/text_edit.c @@ -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); diff --git a/src/base/text_edit.h b/src/base/text_edit.h index 2695ef376..9542bbcb2 100644 --- a/src/base/text_edit.h +++ b/src/base/text_edit.h @@ -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 * 取消选择。 diff --git a/src/widgets/edit.c b/src/widgets/edit.c index eb3c36ab6..80136799a 100644 --- a/src/widgets/edit.c +++ b/src/widgets/edit.c @@ -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; }