Skip to content

Commit

Permalink
improve mledit max_lines
Browse files Browse the repository at this point in the history
  • Loading branch information
xianjimli committed Dec 20, 2024
1 parent eafc2bc commit 29187f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
@@ -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的问题(感谢泽武提供补丁)
Expand Down
28 changes: 17 additions & 11 deletions src/ext_widgets/mledit/mledit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 29187f8

Please sign in to comment.