diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-08-28 11:35:09 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-08-29 09:26:15 +0200 |
commit | 0a81ec14a4c006822509b06396871509140b7a79 (patch) | |
tree | 3455796f8c48fe8c5f202fe3044580c8fe7d8930 /test/functional/api/buffer_spec.lua | |
parent | 794981d9bed7048fb3ee1ada38fcf1ebdace4c53 (diff) | |
download | rneovim-0a81ec14a4c006822509b06396871509140b7a79.tar.gz rneovim-0a81ec14a4c006822509b06396871509140b7a79.tar.bz2 rneovim-0a81ec14a4c006822509b06396871509140b7a79.zip |
fix(api): better topline adjustments in nvim_buf_set_lines
Some more reasonable defaults for topline:
- if topline was replaced with another line, that now becomes topline
- if line was inserted just before topline, display it. This is more
similar to the previous API behavior.
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 136 |
1 files changed, 135 insertions, 1 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 73a8749682..aea1f359e6 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -182,8 +182,8 @@ describe('api/buf', function() {2:[No Name] }| | ]]} - meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"}) + meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"}) screen:expect{grid=[[ | {1:~ }| @@ -198,6 +198,72 @@ describe('api/buf', function() {2:[No Name] [+] }| | ]]} + + -- replacing topline keeps it the topline + meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + wwweeee | + xxx | + yyy | + ^zzz | + {2:[No Name] [+] }| + | + ]]} + + -- inserting just before topline does not scroll up if cursor would be moved + meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + wwweeee | + xxx | + yyy | + ^zzz | + {2:[No Name] [+] }| + | + ]], unchanged=true} + + meths.win_set_cursor(0, {7, 0}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + wwweeee | + xxx | + ^yyy | + zzz | + {2:[No Name] [+] }| + | + ]]} + + meths.buf_set_lines(buf, 4, 4, true, {"mmmeeeee"}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + mmmeeeee | + wwweeee | + xxx | + ^yyy | + {2:[No Name] [+] }| + | + ]]} end) it('of non-current window', function() @@ -237,6 +303,40 @@ describe('api/buf', function() {3:[No Name] [+] }| | ]]} + + -- replacing topline keeps it the topline + meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + wwweeee | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + + -- inserting just before topline scrolls up + meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + mmm | + wwweeee | + xxx | + yyy | + {3:[No Name] [+] }| + | + ]]} end) it('of split windows with same buffer', function() @@ -277,6 +377,40 @@ describe('api/buf', function() {3:[No Name] [+] }| | ]]} + + -- replacing topline keeps it the topline + meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) + screen:expect{grid=[[ + ^aaabbb | + ccc | + ddd | + wwweeee | + xxx | + {2:[No Name] [+] }| + wwweeee | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + + -- inserting just before topline scrolls up + meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) + screen:expect{grid=[[ + ^aaabbb | + ccc | + ddd | + mmm | + wwweeee | + {2:[No Name] [+] }| + mmm | + wwweeee | + xxx | + yyy | + {3:[No Name] [+] }| + | + ]]} end) end) |