Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lua/dap/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,13 @@ function M.layer(buf)
local modifiable = api.nvim_buf_get_option(buf, 'modifiable')
api.nvim_buf_set_option(buf, 'modifiable', true)
if not start and not end_ then
start = api.nvim_buf_line_count(buf) - 1
start = api.nvim_buf_line_count(buf)
-- Avoid inserting a new line at the end of the buffer
-- The case of no lines and one empty line are ambiguous;
-- set_lines(buf, 0, 0) would "preserve" the "empty buffer line" while set_lines(buf, 0, -1) replaces it
-- Need to use regular end_ = start in other cases to support injecting lines in all other cases
if start == 0 and (api.nvim_buf_get_lines(buf, 0, -1, true))[1] == "" then
if start == 1 and (api.nvim_buf_get_lines(buf, 0, -1, true))[1] == "" then
start = 0
end_ = -1
else
end_ = start
Expand Down
15 changes: 15 additions & 0 deletions tests/ui_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ describe('ui', function()
assert.are.same('bbbb', layer.get(2).item.label)
assert.are.same('', layer.get(3).item.label)
end)

it('can append at the end', function()
layer.render({{ label = "e" }}, render_item, nil, nil, nil)
local lines = api.nvim_buf_get_lines(buf, 0, -1, true)
assert.are.same({
'aa',
'bbb',
'bbbb',
'',
'dd',
'e',
}, lines)
assert.are.same('dd', layer.get(4).item.label)
assert.are.same('e', layer.get(5).item.label)
end)
end)

local opts = {
Expand Down