diff --git a/init.lua b/init.lua index ade761f..44d9e92 100644 --- a/init.lua +++ b/init.lua @@ -99,29 +99,26 @@ local function show_proposal_details(player_name, proposal_index) -- Construct comments string with proper escaping and formatting local comments_str = "" for commenter, comment in pairs(proposal.comments) do - -- Escape each comment and add it to the string - comments_str = comments_str .. minetest.formspec_escape(commenter .. ":\n" .. comment) .. "\n\n" + -- Ensure each comment is properly escaped + comments_str = comments_str .. minetest.formspec_escape(commenter .. ":") .. "\n" .. minetest.formspec_escape(comment) .. "\n\n" end - -- Remove the last newline characters - comments_str = comments_str:gsub("\n\n$", "") -- Comments textarea with a scrollbar formspec = formspec .. "scroll_container[0.5,6.5;11,3;scrollbar;vertical]" .. - "textarea[0.25,0.25;10.5,4;;;" .. comments_str .. ";true]" .. + "textarea[0.25,0.25;10.5,4;comments_box;;" .. minetest.formspec_escape(comments_str) .. ";false]" .. "scroll_container_end[]" - -- Edit and Delete Comment buttons only if the player has commented - if has_commented then - formspec = formspec .. "button[0.5,10;3,1;edit_comment;Edit Comment]" .. - "button[4,10;3,1;delete_comment;Delete Comment]" + -- Buttons for adding, editing, or deleting a comment + if not is_author then + if not has_commented then + formspec = formspec .. "button[0.5,10;3,1;add_comment;Add Comment]" + else + formspec = formspec .. "button[0.5,10;3,1;edit_comment;Edit Comment]" .. + "button[4,10;3,1;delete_comment;Delete Comment]" + end end - -- Add Comment button only if the player has not commented and is not the author - if not has_commented and not is_author then - formspec = formspec .. "button[0.5,10;3,1;add_comment;Add Comment]" - end - - -- Edit and Delete Proposal buttons if the player has privileges or is the author + -- Edit and Delete Proposal buttons if the player has admin privileges or is the author if player_has_privilege or is_author then formspec = formspec .. "button[0.5,11;3,1;edit_proposal;Edit Proposal]" .. "button[4,11;3,1;delete_proposal;Delete Proposal]" @@ -133,6 +130,7 @@ local function show_proposal_details(player_name, proposal_index) end + -- Function to show the edit proposal formspec local function show_edit_proposal_formspec(player_name, proposal_index) local proposal = proposals[proposal_index]