mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 14:14:24 -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
|
||||||
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
|
-- image stuff
|
||||||
-- ----------------------------------------------------------------------------
|
-- ----------------------------------------------------------------------------
|
||||||
@@ -2009,7 +2015,7 @@ local function CreateNoteSelectTemplate(opts)
|
|||||||
-- vim.ui.input causes ppl problems - see issue #4
|
-- vim.ui.input causes ppl problems - see issue #4
|
||||||
-- vim.ui.input({ prompt = "Title: " }, on_create_with_template)
|
-- vim.ui.input({ prompt = "Title: " }, on_create_with_template)
|
||||||
local title = vim.fn.input("Title: ")
|
local title = vim.fn.input("Title: ")
|
||||||
title = title:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
title = strip_extension(title, M.Cfg.extension)
|
||||||
if #title > 0 then
|
if #title > 0 then
|
||||||
on_create_with_template(opts, title)
|
on_create_with_template(opts, title)
|
||||||
end
|
end
|
||||||
@@ -2086,7 +2092,7 @@ local function CreateNote(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local title = vim.fn.input("Title: ")
|
local title = vim.fn.input("Title: ")
|
||||||
title = title:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
title = strip_extension(title, M.Cfg.extension)
|
||||||
if #title > 0 then
|
if #title > 0 then
|
||||||
on_create(opts, title)
|
on_create(opts, title)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user