From 6a10a7929421d6e696e46bbc5aa5627a8cbcf61d Mon Sep 17 00:00:00 2001 From: Coutinho de Souza Date: Sat, 26 Oct 2024 18:46:34 +0000 Subject: [PATCH] feat: use generate_note_filename for renaming notes (#345) --- lua/telekasten.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 6a0b771..08188a2 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -1610,7 +1610,20 @@ end local function RenameNote() local oldfile = Pinfo:new({ filepath = vim.fn.expand("%:p"), M.Cfg }) - fileutils.prompt_title(M.Cfg.extension, oldfile.title, function(newname) + local oldtitle = oldfile.title + local curuuid = "" + local escapedsep = M.Cfg.uuid_sep:gsub("[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%1") + + if M.Cfg.new_note_filename == "uuid-title" then + curuuid, oldtitle = + oldfile.title:match("^(.-)" .. escapedsep .. "(.+)$") + elseif M.Cfg.new_note_filename == "title-uuid" then + oldtitle, curuuid = + oldfile.title:match("^(.+)" .. escapedsep .. "(.-)$") + end + + fileutils.prompt_title(M.Cfg.extension, oldtitle, function(newname) + newname = generate_note_filename(curuuid, newname) local newpath = newname:match("(.*/)") or "" newpath = M.Cfg.home .. "/" .. newpath