Merge pull request #72 from fsouza/fix-empty-line-preview

Fix empty line in the builtin previewer
main
ibhagwan 3 years ago committed by GitHub
commit fa6c80a8fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -314,7 +314,16 @@ function Previewer:display_entry(entry)
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
local ok = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, vim.split(data, "[\r]?\n"))
local lines = vim.split(data, "[\r]?\n")
-- if file ends in new line, don't write an empty string as the last
-- line.
if data:sub(#data, #data) == "\n" or data:sub(#data-1,#data) == "\r\n" then
table.remove(lines)
end
local ok = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, lines)
if not ok then
return
end

Loading…
Cancel
Save