From 7ce918d3b2f73a394b7afb4406186197ee6123ab Mon Sep 17 00:00:00 2001 From: Ian Mancini Date: Fri, 3 Mar 2023 23:56:28 -0300 Subject: [PATCH] feat: add function to insert zk notes --- lua/plugins/notes.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lua/plugins/notes.lua b/lua/plugins/notes.lua index 2363a69..77edfc8 100644 --- a/lua/plugins/notes.lua +++ b/lua/plugins/notes.lua @@ -84,6 +84,21 @@ vim.api.nvim_create_autocmd("BufEnter", { end, "Find note match", }, + i = { + function() + require("zk").pick_notes(nil, nil, function(notes) + local vstartr, vstartc = unpack(vim.api.nvim_win_get_cursor(0)) + local _, vendr, vendc, _ = unpack(vim.fn.getpos("v")) + + local link = "[" .. notes[1].title .. "](" .. notes[1].path .. ")" + print(vstartr, vstartc, vendr, vendc, vstartc + #link) + + vim.api.nvim_buf_set_text(0, vstartr - 1, vstartc - 2, vendr - 1, vendc, { link }) + vim.api.nvim_win_set_cursor(0, { vendr, vstartc + #link - 3 }) + end) + end, + "Insert note link", + }, }, { mode = "v", bufnr = bufnr, @@ -103,6 +118,17 @@ vim.api.nvim_create_autocmd("BufEnter", { end, "Show note links", }, + i = { + function() + require("zk").pick_notes(nil, nil, function(notes) + local cur = vim.api.nvim_win_get_cursor(0) + local link = "[" .. notes[1].title .. "](" .. notes[1].path .. ")" + vim.api.nvim_buf_set_text(0, cur[1] - 1, cur[2], cur[1] - 1, cur[2], { link }) + vim.api.nvim_win_set_cursor(0, { cur[1], cur[2] + #link }) + end) + end, + "Insert note link", + }, }, { mode = "n", bufnr = bufnr,