aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-08-30 11:53:58 +0200
committerbfredl <bjorn.linse@gmail.com>2023-08-30 12:01:35 +0200
commitb051b131f5ce99ffe1b1bc22a2032ebc886e4e35 (patch)
treea5592925d232f2c6ea35f962f28aee89f6de3798 /src
parent62869da11ceeb1309850fe704bae3f29724e454c (diff)
downloadrneovim-b051b131f5ce99ffe1b1bc22a2032ebc886e4e35.tar.gz
rneovim-b051b131f5ce99ffe1b1bc22a2032ebc886e4e35.tar.bz2
rneovim-b051b131f5ce99ffe1b1bc22a2032ebc886e4e35.zip
fix(api): nvim_buf_get_offset in a new buffer with zero or one lines
fixes #24930
Diffstat (limited to 'src')
-rw-r--r--src/nvim/memline.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 5839061aac..123e9d0a0b 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -3934,6 +3934,11 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
if (buf->b_ml.ml_usedchunks == -1
|| buf->b_ml.ml_chunksize == NULL
|| lnum < 0) {
+ // memline is currently empty. Although if it is loaded,
+ // it behaves like there is one empty line.
+ if (!ffdos && buf->b_ml.ml_mfp && (lnum == 1 || lnum == 2)) {
+ return lnum - 1;
+ }
return -1;
}