vim-patch:9.1.0883: message history cleanup is missing some tests (#31331)

Problem:  message history cleanup is missing some tests
Solution: Add tests, refactor common code into did_set_msghistory()
          (Shougo Matsushita)

closes: vim/vim#16078

9f860a14c3

Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Co-authored-by: Milly <milly.ca@gmail.com>
This commit is contained in:
zeertzjq
2024-11-24 22:36:33 +08:00
committed by GitHub
parent ef4f13d85c
commit 5c60306442
6 changed files with 47 additions and 5 deletions

View File

@@ -982,11 +982,6 @@ static void add_msg_hist_multihl(const char *s, int len, int hl_id, bool multili
return;
}
// Don't let the message history get too big
while (msg_hist_len > p_mhi) {
delete_first_msg();
}
// allocate an entry and add the message at the end of the history
struct msg_hist *p = xmalloc(sizeof(struct msg_hist));
if (s) {
@@ -1018,6 +1013,8 @@ static void add_msg_hist_multihl(const char *s, int len, int hl_id, bool multili
first_msg_hist = last_msg_hist;
}
msg_hist_len++;
check_msg_hist();
}
/// Delete the first (oldest) message from the history.
@@ -1041,6 +1038,14 @@ int delete_first_msg(void)
return OK;
}
void check_msg_hist(void)
{
// Don't let the message history get too big
while (msg_hist_len > 0 && msg_hist_len > p_mhi) {
(void)delete_first_msg();
}
}
/// :messages command implementation
void ex_messages(exarg_T *eap)
FUNC_ATTR_NONNULL_ALL