aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/buffer_spec.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-08-29 10:03:04 +0200
committerGitHub <noreply@github.com>2023-08-29 10:03:04 +0200
commit97badc9ac41e0c90d6e4a4389c3b7c022a5dfb88 (patch)
tree196412487f11db53d78ce91c563f42158955148f /test/functional/api/buffer_spec.lua
parentffb340bf63af42ac347e23e0488898adc4391328 (diff)
parent0a81ec14a4c006822509b06396871509140b7a79 (diff)
downloadrneovim-97badc9ac41e0c90d6e4a4389c3b7c022a5dfb88.tar.gz
rneovim-97badc9ac41e0c90d6e4a4389c3b7c022a5dfb88.tar.bz2
rneovim-97badc9ac41e0c90d6e4a4389c3b7c022a5dfb88.zip
Merge pull request #24912 from bfredl/topline2
fix(api): better topline adjustments in nvim_buf_set_lines
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r--test/functional/api/buffer_spec.lua136
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)