diff options
author | Raphael <glephunter@gmail.com> | 2023-10-29 15:44:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-29 15:44:52 +0800 |
commit | 0da27e9bdec14acf82731c4d5e0ad7d673697af7 (patch) | |
tree | ae702350cb6180f053d6d1d2d2d84e7bd6b59073 /src/nvim/api/buffer.c | |
parent | 82b1a389ba98f5f8e8d6c9d7485386be272a22df (diff) | |
download | rneovim-0da27e9bdec14acf82731c4d5e0ad7d673697af7.tar.gz rneovim-0da27e9bdec14acf82731c4d5e0ad7d673697af7.tar.bz2 rneovim-0da27e9bdec14acf82731c4d5e0ad7d673697af7.zip |
fix(api): load buffer first on nvim_buf_set_lines (#25823)
Fix #22670
Fix #8659
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 64dddea5b8..86298efe08 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -359,6 +359,14 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ return; } + // loaded buffer first if it's not loaded + if (buf->b_ml.ml_mfp == NULL) { + if (!buf_ensure_loaded(buf)) { + api_set_error(err, kErrorTypeException, "Failed to load buffer"); + return; + } + } + bool oob = false; start = normalize_index(buf, start, true, &oob); end = normalize_index(buf, end, true, &oob); @@ -396,10 +404,6 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ goto end; } - if (!buf_ensure_loaded(buf)) { - goto end; - } - if (u_save_buf(buf, (linenr_T)(start - 1), (linenr_T)end) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to save undo information"); goto end; @@ -537,6 +541,14 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In return; } + // loaded buffer first if it's not loaded + if (buf->b_ml.ml_mfp == NULL) { + if (!buf_ensure_loaded(buf)) { + api_set_error(err, kErrorTypeException, "Failed to load buffer"); + return; + } + } + bool oob = false; // check range is ordered and everything! @@ -645,10 +657,6 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In goto end; } - if (!buf_ensure_loaded(buf)) { - goto end; - } - // Small note about undo states: unlike set_lines, we want to save the // undo state of one past the end_row, since end_row is inclusive. if (u_save_buf(buf, (linenr_T)start_row - 1, (linenr_T)end_row + 1) == FAIL) { |