diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/buffer.c | 14 | ||||
-rw-r--r-- | src/nvim/buffer_updates.c | 4 |
2 files changed, 9 insertions, 9 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; diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index bee7db1e98..2c92fb26b2 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -81,7 +81,7 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb linedata.size = line_count; linedata.items = xcalloc(line_count, sizeof(Object)); - buf_collect_lines(buf, line_count, 1, true, &linedata, NULL, NULL); + buf_collect_lines(buf, line_count, 1, 0, true, &linedata, NULL, NULL); } args.items[4] = ARRAY_OBJ(linedata); @@ -242,7 +242,7 @@ void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added, STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM"); linedata.size = (size_t)num_added; linedata.items = xcalloc((size_t)num_added, sizeof(Object)); - buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata, + buf_collect_lines(buf, (size_t)num_added, firstline, 0, true, &linedata, NULL, NULL); } args.items[4] = ARRAY_OBJ(linedata); |