diff --git a/docs/changes.md b/docs/changes.md index 952d9bcd4..e65dc28e5 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,8 @@ # 最新动态 +2024/12/20 + * 同步mledit的max_lines初始值与text_edit的max_rows初始值;修复mledit在max_lines为0时的字符串裁剪错误(感谢泽武提供补丁) + 2024/12/19 * 增加 wchar32 以及相关函数。 * 修复mledit在设置文本时没有检查max_chars和max_lines的问题(感谢泽武提供补丁) diff --git a/src/ext_widgets/mledit/mledit.c b/src/ext_widgets/mledit/mledit.c index 81fc9a4d0..334287954 100644 --- a/src/ext_widgets/mledit/mledit.c +++ b/src/ext_widgets/mledit/mledit.c @@ -1132,20 +1132,25 @@ static uint32_t mledit_update_text(widget_t* widget) { } /* handle max_lines */ - for (i = (int32_t)(text->size) - 1; i >= 0; --i) { - if (i > 0 && TWINS_WCHAR_IS_LINE_BREAK(text->str[i - 1], text->str[i])) { - ++line_num; - if (line_num > mledit->max_lines) { - break; - } + if (mledit->max_lines > 0) { + for (i = (int32_t)(text->size) - 1; i >= 0; --i) { + if (i > 0 && TWINS_WCHAR_IS_LINE_BREAK(text->str[i - 1], text->str[i])) { + ++line_num; + if (line_num > mledit->max_lines) { + break; + } - --i; - } else if (WCHAR_IS_LINE_BREAK(text->str[i])) { - ++line_num; - if (line_num > mledit->max_lines) { - break; + --i; + } else if (WCHAR_IS_LINE_BREAK(text->str[i])) { + ++line_num; + if (line_num > mledit->max_lines) { + break; + } } } + } else { + rm_cnt = text->size; + wstr_remove(text, 0, text->size); } if (i >= 0) { rm_cnt += i + 1; @@ -1283,6 +1288,7 @@ static ret_t mledit_init(widget_t* widget) { mledit->right_margin = 0; mledit->bottom_margin = 0; mledit->scroll_line = 1.0f; + mledit->max_lines = 100; wstr_init(&(mledit->temp), 0); wstr_init(&(mledit->last_changing_text), 0); wstr_init(&(mledit->last_changed_text), 0);