Fix: Keep empty lines in discussion tree (#173)

* Docs: Fix typos and remove trailing spaces

* Fix: Split strings by new lines correctly

* Docs: Recommend breakindent option to improve tree nodes indentation

* Fix: Replace whole buffer when creating a new suggestion

Previously, a trailing empty line was left in the buffer.

---------

Co-authored-by: Jakub Bortlík <jakub.bortlik@phonexia.com>
This commit is contained in:
Jakub F. Bortlík
2024-02-10 17:06:56 +01:00
committed by GitHub
parent 132dd60b95
commit d05a23a7d5
7 changed files with 46 additions and 22 deletions

View File

@@ -77,7 +77,7 @@ M.create_comment_suggestion = function()
table.insert(suggestion_lines, backticks)
comment_popup:mount()
vim.api.nvim_buf_set_lines(comment_popup.bufnr, 0, 0, false, suggestion_lines)
vim.api.nvim_buf_set_lines(comment_popup.bufnr, 0, -1, false, suggestion_lines)
state.set_popup_keymaps(comment_popup, function(text)
if range > 0 then
M.confirm_create_comment(text, { start_line = start_line, end_line = end_line })

View File

@@ -259,10 +259,11 @@ end
---Builds a lua list of strings that contain the MR description
M.build_description_lines = function(template_content)
local description_lines = {}
for line in template_content:gmatch("[^\n]+") do
for line in u.split_by_new_lines(template_content) do
table.insert(description_lines, line)
table.insert(description_lines, "")
end
-- TODO: @harrisoncramer Same as in lua/gitlab/actions/summary.lua:114
table.insert(description_lines, "")
return description_lines
end

View File

@@ -92,7 +92,7 @@ end
---@return NuiTree.Node[]
local function build_note_body(note, resolve_info)
local text_nodes = {}
for bodyLine in note.body:gmatch("[^\n]+") do
for bodyLine in u.split_by_new_lines(note.body) do
local line = attach_uuid(bodyLine)
table.insert(
text_nodes,

View File

@@ -148,7 +148,7 @@ M.see_logs = function()
end
local lines = {}
for line in file:gmatch("[^\n]+") do
for line in u.split_by_new_lines(file) do
table.insert(lines, line)
end

View File

@@ -108,10 +108,13 @@ M.build_description_lines = function()
local description_lines = {}
local description = state.INFO.description
for line in description:gmatch("[^\n]+") do
for line in u.split_by_new_lines(description) do
table.insert(description_lines, line)
table.insert(description_lines, "")
end
-- TODO: @harrisoncramer Not sure whether the following line should be here at all. It definitely
-- didn't belong into the for loop, since it inserted an empty line after each line. But maybe
-- there is a purpose for an empty line at the end of the buffer?
table.insert(description_lines, "")
return description_lines
end