diff options
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r-- | src/nvim/lua/stdlib.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 8f58fd1a1a..22ee0a1c98 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -107,15 +107,15 @@ static int regex_match_line(lua_State *lstate) } char *line = ml_get_buf(buf, rownr + 1); - size_t len = strlen(line); + colnr_T len = ml_get_buf_len(buf, rownr + 1); - if (start < 0 || (size_t)start > len) { + if (start < 0 || start > len) { return luaL_error(lstate, "invalid start"); } char save = NUL; if (end >= 0) { - if ((size_t)end > len || end < start) { + if (end > len || end < start) { return luaL_error(lstate, "invalid end"); } save = line[end]; @@ -449,7 +449,7 @@ int nlua_getvar(lua_State *lstate) if (di == NULL) { return 0; // nil } - nlua_push_typval(lstate, &di->di_tv, false); + nlua_push_typval(lstate, &di->di_tv, 0); return 1; } @@ -543,14 +543,27 @@ static int nlua_iconv(lua_State *lstate) return 1; } -// Update foldlevels (e.g., by evaluating 'foldexpr') for all lines in the current window without -// invoking other side effects. Unlike `zx`, it does not close manually opened folds and does not -// open folds under the cursor. +// Update foldlevels (e.g., by evaluating 'foldexpr') for the given line range in the given window, +// without invoking other side effects. Unlike `zx`, it does not close manually opened folds and +// does not open folds under the cursor. static int nlua_foldupdate(lua_State *lstate) { - curwin->w_foldinvalid = true; // recompute folds - foldUpdate(curwin, 1, (linenr_T)MAXLNUM); - curwin->w_foldinvalid = false; + handle_T window = (handle_T)luaL_checkinteger(lstate, 1); + win_T *win = handle_get_window(window); + if (!win) { + return luaL_error(lstate, "invalid window"); + } + // input is zero-based end-exclusive range + linenr_T top = (linenr_T)luaL_checkinteger(lstate, 2) + 1; + if (top < 1 || top > win->w_buffer->b_ml.ml_line_count) { + return luaL_error(lstate, "invalid top"); + } + linenr_T bot = (linenr_T)luaL_checkinteger(lstate, 3); + if (top > bot) { + return luaL_error(lstate, "invalid bot"); + } + + foldUpdate(win, top, bot); return 0; } |