mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
fix: note title ending removed when it matches parts of extension (#119)
* fix: note title ending removed when it matches parts of extension By using [] we provide a character set rather than a direct match with (). Lua patterns don't allow N-captures with (), so we continue executing the pattern until there are no more substitutions being executed. fixes #118 * fix: refactor extension stripping from title Don't worry about n-capture, once is enough. Turned it into a fn so it can be used elsewhere. refs #118
This commit is contained in:
@@ -341,6 +341,12 @@ local function save_all_tk_buffers()
|
||||
end
|
||||
end
|
||||
|
||||
-- strip an extension from a file name, escaping "." properly, eg:
|
||||
-- strip_extension("path/Filename.md", ".md") -> "path/Filename"
|
||||
local function strip_extension(str, ext)
|
||||
return str:gsub("(" .. ext:gsub("%.", "%%.") .. ")$", "")
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- image stuff
|
||||
-- ----------------------------------------------------------------------------
|
||||
@@ -2009,7 +2015,7 @@ local function CreateNoteSelectTemplate(opts)
|
||||
-- vim.ui.input causes ppl problems - see issue #4
|
||||
-- vim.ui.input({ prompt = "Title: " }, on_create_with_template)
|
||||
local title = vim.fn.input("Title: ")
|
||||
title = title:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
||||
title = strip_extension(title, M.Cfg.extension)
|
||||
if #title > 0 then
|
||||
on_create_with_template(opts, title)
|
||||
end
|
||||
@@ -2086,7 +2092,7 @@ local function CreateNote(opts)
|
||||
end
|
||||
|
||||
local title = vim.fn.input("Title: ")
|
||||
title = title:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
||||
title = strip_extension(title, M.Cfg.extension)
|
||||
if #title > 0 then
|
||||
on_create(opts, title)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user