diff options
author | luukvbaal <31730729+luukvbaal@users.noreply.github.com> | 2022-11-07 04:10:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-06 19:10:09 -0800 |
commit | 9f125371e08f4bbb38b84f323608d01d35895a3a (patch) | |
tree | 77d9a26a6812f2e9baf3225d531722de1e994717 /src/nvim/screen.c | |
parent | ce198102bda11552397181eab044b10c96645dbd (diff) | |
download | rneovim-9f125371e08f4bbb38b84f323608d01d35895a3a.tar.gz rneovim-9f125371e08f4bbb38b84f323608d01d35895a3a.tar.bz2 rneovim-9f125371e08f4bbb38b84f323608d01d35895a3a.zip |
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
Diffstat (limited to 'src/nvim/screen.c')
-rw-r--r-- | src/nvim/screen.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c index cd1d6553cb..377927ba4d 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -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) { |