mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 14:14:24 -05:00
33 lines
875 B
Lua
33 lines
875 B
Lua
local M = {}
|
|
|
|
-- 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
|
|
|
|
function M.prompt_title(ext, defaultFile, callback)
|
|
local canceledStr = "__INPUT_CANCELLED__"
|
|
|
|
vim.ui.input({
|
|
prompt = "Title: ",
|
|
cancelreturn = canceledStr,
|
|
completion = "file",
|
|
default = defaultFile,
|
|
}, function(title)
|
|
if not title then
|
|
title = ""
|
|
end
|
|
if title == canceledStr then
|
|
vim.cmd("echohl WarningMsg")
|
|
vim.cmd("echomsg 'Note creation cancelled!'")
|
|
vim.cmd("echohl None")
|
|
else
|
|
title = strip_extension(title, ext)
|
|
callback(title)
|
|
end
|
|
end)
|
|
end
|
|
|
|
return M
|