Skip to content

Commit

Permalink
improve edit_ex
Browse files Browse the repository at this point in the history
  • Loading branch information
xianjimli committed Mar 7, 2025
1 parent 241de3c commit ffb74b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

2025/03/07
* edit_ex兼容旧项目(感谢兆坤提供补丁)
* 完善 edit_ex(感谢兆坤提供补丁)

2025/03/05
* 去除函数定义了没使用的警告(感谢兆坤提供补丁)
Expand Down
14 changes: 8 additions & 6 deletions src/ext_widgets/edit_ex/edit_ex_suggest_words_helper.inc
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,10 @@ typedef struct _edit_ex_update_suggest_words_popup_ctx_t {
edit_ex_t* edit_ex;
widget_t* list_view;
widget_t* scroll_view;
darray_t* used_format_names;
uint32_t curr_index;
int32_t item_width;
darray_t* used_format_names;
bool_t index_changed : 1;
} edit_ex_update_suggest_words_popup_ctx_t;

static ret_t edit_ex_update_suggest_words_popup_on_item_visit(void* ctx, const void* data) {
Expand Down Expand Up @@ -382,7 +383,6 @@ static ret_t edit_ex_update_suggest_words_popup_on_visit(void* ctx, const void*
edit_ex_update_suggest_words_popup_ctx_t* actx = (edit_ex_update_suggest_words_popup_ctx_t*)(ctx);
const value_t* v = (const value_t*)data;
widget_t* item = NULL;
bool_t index_changed = FALSE;
return_value_if_fail(actx != NULL && v != NULL, RET_BAD_PARAMS);
return_value_if_fail(
actx->edit_ex != NULL && actx->scroll_view != NULL && actx->list_view != NULL,
Expand Down Expand Up @@ -418,7 +418,7 @@ static ret_t edit_ex_update_suggest_words_popup_on_visit(void* ctx, const void*
if (tk_str_eq(iter_format_name, format_name)) {
item = iter;
widget_restack(item, actx->curr_index);
index_changed = TRUE;
actx->index_changed = TRUE;
break;
}
WIDGET_FOR_EACH_CHILD_END()
Expand All @@ -429,7 +429,7 @@ static ret_t edit_ex_update_suggest_words_popup_on_visit(void* ctx, const void*
item = widget_clone(model, actx->scroll_view);
return_value_if_fail(item != NULL, RET_OOM);
widget_restack(item, actx->curr_index);
index_changed = TRUE;
actx->index_changed = TRUE;
}

WIDGET_FOR_EACH_CHILD_BEGIN(item, iter, i)
Expand All @@ -439,16 +439,18 @@ static ret_t edit_ex_update_suggest_words_popup_on_visit(void* ctx, const void*
const char* suggest = value_str(v);
return_value_if_fail(suggest != NULL, RET_FAIL);

actx->index_changed = FALSE;

item = widget_get_child(actx->scroll_view, actx->curr_index);
if (item == NULL) {
item = edit_ex_suggest_words_create_item(actx->edit_ex, actx->scroll_view);
return_value_if_fail(item != NULL, RET_OOM);
index_changed = TRUE;
actx->index_changed = TRUE;
}
widget_set_text_utf8(item, suggest);
}

if (index_changed) {
if (actx->index_changed) {
ret_t ret = RET_OK;
value_t tmp;
if ((actx->curr_index + 1) % 2 != 0) { /* 0 为第一项,所以是奇数项 */
Expand Down

0 comments on commit ffb74b8

Please sign in to comment.