aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2023-12-09 17:28:28 +0800
committerglepnir <glephunter@gmail.com>2023-12-12 13:49:04 +0800
commitd95e3a4c9c8f468158a1f1f23921ebbaae75cf8b (patch)
tree810c2a3176b2a5bbebf10cc412697cedda359bfb
parent0b74ad0a641f28d9d3da5353e98372d87078bd9d (diff)
downloadrneovim-d95e3a4c9c8f468158a1f1f23921ebbaae75cf8b.tar.gz
rneovim-d95e3a4c9c8f468158a1f1f23921ebbaae75cf8b.tar.bz2
rneovim-d95e3a4c9c8f468158a1f1f23921ebbaae75cf8b.zip
fix: use no_ff instead of ffdos as condition
Problem: line2byte behavior is changed after commit b051b13. It no longer return `-1` on empty buffer. Solution: use `nof_ff` instead of `!ff_dos` as condition. Then compatible behavior of line2byte() is restored.
-rw-r--r--src/nvim/memline.c2
-rw-r--r--test/functional/api/buffer_spec.lua1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 5e768839ba..709c7f3d40 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -3907,7 +3907,7 @@ int ml_find_line_or_offset(buf_T *buf, linenr_T lnum, int *offp, bool no_ff)
|| 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)) {
+ if (no_ff && buf->b_ml.ml_mfp && (lnum == 1 || lnum == 2)) {
return lnum - 1;
}
return -1;
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index 6ed9aa574a..ed93135acb 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -1876,6 +1876,7 @@ describe('api/buf', function()
it('works in empty buffer', function()
eq(0, get_offset(0))
eq(1, get_offset(1))
+ eq(-1, funcs.line2byte('$'))
end)
it('works in buffer with one line inserted', function()