From e256cbaa9588f08c8df4b327e68f6e11d6a012af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Mun=CC=83oz?= Date: Wed, 24 Feb 2021 23:15:41 +0100 Subject: [PATCH] add folds for comments --- lua/octo/folds.lua | 3 +++ lua/octo/init.lua | 8 ++++++++ lua/octo/writers.lua | 10 +++++++++- plugin/octo.vim | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lua/octo/folds.lua diff --git a/lua/octo/folds.lua b/lua/octo/folds.lua new file mode 100644 index 000000000..3770c6cf8 --- /dev/null +++ b/lua/octo/folds.lua @@ -0,0 +1,3 @@ +function _G.OctoFoldText() + return "..." +end diff --git a/lua/octo/init.lua b/lua/octo/init.lua index 5ecfe8d89..76b672a21 100644 --- a/lua/octo/init.lua +++ b/lua/octo/init.lua @@ -148,6 +148,8 @@ function M.create_buffer(type, obj, repo, create) bufnr = api.nvim_get_current_buf() end + api.nvim_set_current_buf(bufnr) + -- clear buffer api.nvim_buf_set_lines(bufnr, 0, -1, false, {}) @@ -159,6 +161,12 @@ function M.create_buffer(type, obj, repo, create) -- configure buffer api.nvim_buf_set_option(bufnr, "filetype", "octo_issue") api.nvim_buf_set_option(bufnr, "buftype", "acwrite") + vim.cmd [[setlocal fillchars=fold:⠀,foldopen:⠀,foldclose:⠀,foldsep:⠀]] + vim.cmd [[setlocal foldtext=v:lua.OctoFoldText()]] + vim.cmd [[setlocal foldmethod=manual]] + vim.cmd [[setlocal foldenable]] + vim.cmd [[setlocal foldcolumn=1]] + vim.cmd [[setlocal foldlevelstart=99]] -- register issue api.nvim_buf_set_var(bufnr, "iid", iid) diff --git a/lua/octo/writers.lua b/lua/octo/writers.lua index 85c84da54..76d5d549e 100644 --- a/lua/octo/writers.lua +++ b/lua/octo/writers.lua @@ -342,6 +342,7 @@ function M.write_details(bufnr, issue, update) end function M.write_comment(bufnr, comment, line) + -- heading line = line or api.nvim_buf_line_count(bufnr) + 1 M.write_block({"", ""}, {bufnr = bufnr, mark = false, line = line}) @@ -360,8 +361,10 @@ function M.write_comment(bufnr, comment, line) local comment_vt_ns = api.nvim_buf_set_virtual_text(bufnr, 0, line - 1, header_vt, {}) + local fold_start_line = line + 2 + -- body - line = line + 2 + line = fold_start_line local comment_body = string.gsub(comment.body, "\r\n", "\n") if vim.startswith(comment_body, constants.NO_BODY_MSG) or util.is_blank(comment_body) then comment_body = " " @@ -396,6 +399,11 @@ function M.write_comment(bufnr, comment, line) } ) api.nvim_buf_set_var(bufnr, "comments", comments_metadata) + + -- add fold + vim.cmd(format("%d,%dfold", fold_start_line - 1, line)) + vim.cmd(format("%d,%dfoldopen!", fold_start_line - 1, line)) + end function M.write_diff_hunk(bufnr, diff_hunk, start_line) diff --git a/plugin/octo.vim b/plugin/octo.vim index 5f151d7db..00720ab6b 100644 --- a/plugin/octo.vim +++ b/plugin/octo.vim @@ -79,6 +79,9 @@ augroup END " sign definitions lua require'octo.signs'.setup() +" folds +lua require'octo.folds' + " logged-in user if !exists("g:octo_loggedin_user") let g:octo_loggedin_user = v:null