refactor: click definition functions #20923

Need this part of `win_redr_custom()` in `drawline.c` for #20621.
Another refactor is pending in https://github.com/vim/vim/pull/11467
This commit is contained in:
luukvbaal
2022-11-07 04:10:09 +01:00
committed by GitHub
parent ce198102bd
commit 9f125371e0
2 changed files with 48 additions and 40 deletions

View File

@@ -598,6 +598,49 @@ void stl_clear_click_defs(StlClickDefinition *const click_defs, const long click
}
}
/// Allocate or resize the click definitions array if needed.
StlClickDefinition *stl_alloc_click_defs(StlClickDefinition *cdp, long width, size_t *size)
{
if (*size < (size_t)width) {
xfree(cdp);
*size = (size_t)width;
cdp = xcalloc(*size, sizeof(StlClickDefinition));
}
return cdp;
}
/// Fill the click definitions array if needed.
void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_recs, char *buf,
int width, bool tabline)
{
if (click_defs == NULL) {
return;
}
int col = 0;
int len = 0;
StlClickDefinition cur_click_def = {
.type = kStlClickDisabled,
};
for (int i = 0; click_recs[i].start != NULL; i++) {
len += vim_strnsize(buf, (int)(click_recs[i].start - buf));
while (col < len) {
click_defs[col++] = cur_click_def;
}
buf = (char *)click_recs[i].start;
cur_click_def = click_recs[i].def;
if (!tabline && !(cur_click_def.type == kStlClickDisabled
|| cur_click_def.type == kStlClickFuncRun)) {
// window bar and status line only support click functions
cur_click_def.type = kStlClickDisabled;
}
}
while (col < width) {
click_defs[col++] = cur_click_def;
}
}
/// Set cursor to its position in the current window.
void setcursor(void)
{