mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
fix(api): nvim_buf_get_offset in a new buffer with zero or one lines
fixes #24930
This commit is contained in:
parent
62869da11c
commit
b051b131f5
@ -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
|
if (buf->b_ml.ml_usedchunks == -1
|
||||||
|| buf->b_ml.ml_chunksize == NULL
|
|| buf->b_ml.ml_chunksize == NULL
|
||||||
|| lnum < 0) {
|
|| 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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1151,6 +1151,18 @@ describe('api/buf', function()
|
|||||||
eq(6, bufmeths.get_offset(1,1))
|
eq(6, bufmeths.get_offset(1,1))
|
||||||
command("bunload! 1")
|
command("bunload! 1")
|
||||||
eq(-1, bufmeths.get_offset(1,1))
|
eq(-1, bufmeths.get_offset(1,1))
|
||||||
|
eq(-1, bufmeths.get_offset(1,0))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('works in empty buffer', function()
|
||||||
|
eq(0, get_offset(0))
|
||||||
|
eq(1, get_offset(1))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('works in buffer with one line inserted', function()
|
||||||
|
feed('itext')
|
||||||
|
eq(0, get_offset(0))
|
||||||
|
eq(5, get_offset(1))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user