diff options
author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-09-17 23:34:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-17 23:34:28 +0200 |
commit | 6dc815530b7b127c5b5e0912783c3f2118cb184f (patch) | |
tree | 284d2d497a27ee53593a2e69385f6627de2befc9 /src | |
parent | 2d9ae2166470b164bfce15333c85d00b93ff83f4 (diff) | |
download | rneovim-6dc815530b7b127c5b5e0912783c3f2118cb184f.tar.gz rneovim-6dc815530b7b127c5b5e0912783c3f2118cb184f.tar.bz2 rneovim-6dc815530b7b127c5b5e0912783c3f2118cb184f.zip |
buf_updates: fix updates for empty buffers (#12926)
On empty buffers, when editing the first line, the line is buffered, causing offset to be < 0. While the buffer is not actually empty, the buffered line has not been flushed (and should not be) yet, so the call is valid but an edge case.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/extmark.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index ba94f55a50..17141f12fd 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -568,8 +568,18 @@ void extmark_splice(buf_T *buf, int new_row, colnr_T new_col, bcount_t new_byte, ExtmarkOp undo) { - long offset = ml_find_line_or_offset(buf, start_row+1, NULL, true); - extmark_splice_impl(buf, start_row, start_col, offset+start_col, + long offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true); + + // On empty buffers, when editing the first line, the line is buffered, + // causing offset to be < 0. While the buffer is not actually empty, the + // buffered line has not been flushed (and should not be) yet, so the call is + // valid but an edge case. + // + // TODO(vigoux): maybe the is a better way of testing that ? + if (offset < 0 && buf->b_ml.ml_chunksize == NULL) { + offset = 0; + } + extmark_splice_impl(buf, start_row, start_col, offset + start_col, old_row, old_col, old_byte, new_row, new_col, new_byte, undo); } |