aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/buffer.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-11-15 21:27:42 +0000
committerGitHub <noreply@github.com>2022-11-15 21:27:42 +0000
commitfa7e1e26019112ff9e2ea42626995f04e2a4e032 (patch)
tree779343f8ac8b3f2471c67bb53598499ce64b5f0f /src/nvim/api/buffer.c
parentfd54194a4fd477d15a12c69106126514952eb563 (diff)
downloadrneovim-fa7e1e26019112ff9e2ea42626995f04e2a4e032.tar.gz
rneovim-fa7e1e26019112ff9e2ea42626995f04e2a4e032.tar.bz2
rneovim-fa7e1e26019112ff9e2ea42626995f04e2a4e032.zip
fix(api): nvim_buf_get_text regression (#21071)
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r--src/nvim/api/buffer.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 1101689391..0a31286df7 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -311,7 +311,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
init_line_array(lstate, &rv, size);
- if (!buf_collect_lines(buf, size, (linenr_T)start, (channel_id != VIML_INTERNAL_CALL), &rv,
+ if (!buf_collect_lines(buf, size, (linenr_T)start, 0, (channel_id != VIML_INTERNAL_CALL), &rv,
lstate, err)) {
goto end;
}
@@ -857,9 +857,8 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer,
}
if (size > 2) {
- Array tmp = ARRAY_DICT_INIT;
- tmp.items = &rv.items[1];
- if (!buf_collect_lines(buf, size - 2, (linenr_T)start_row + 1, replace_nl, &tmp, lstate, err)) {
+ if (!buf_collect_lines(buf, size - 2, (linenr_T)start_row + 1, 1, replace_nl, &rv, lstate,
+ err)) {
goto end;
}
}
@@ -1464,12 +1463,13 @@ static void push_linestr(lua_State *lstate, Array *a, const char *s, size_t len,
/// @param n Number of lines to collect
/// @param replace_nl Replace newlines ("\n") with NUL
/// @param start Line number to start from
+/// @param start_idx First index to push to
/// @param[out] l If not NULL, Lines are copied here
/// @param[out] lstate If not NULL, Lines are pushed into a table onto the stack
/// @param err[out] Error, if any
/// @return true unless `err` was set
-bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, bool replace_nl, Array *l,
- lua_State *lstate, Error *err)
+bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, int start_idx, bool replace_nl,
+ Array *l, lua_State *lstate, Error *err)
{
for (size_t i = 0; i < n; i++) {
linenr_T lnum = start + (linenr_T)i;
@@ -1482,7 +1482,7 @@ bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, bool replace_nl, Ar
}
char *bufstr = ml_get_buf(buf, lnum, false);
- push_linestr(lstate, l, bufstr, strlen(bufstr), (int)i, replace_nl);
+ push_linestr(lstate, l, bufstr, strlen(bufstr), start_idx + (int)i, replace_nl);
}
return true;