mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 14:14:24 -05:00
refact(prompt_title): move strip_extension to utils
This commit is contained in:
@@ -1,18 +1,27 @@
|
||||
local M = {}
|
||||
|
||||
function M.prompt_title(callback)
|
||||
-- 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, callback)
|
||||
local canceledStr = "__INPUT_CANCELLED__"
|
||||
|
||||
vim.ui.input({
|
||||
prompt = "Title: ",
|
||||
default = "",
|
||||
cancelreturn = canceledStr,
|
||||
}, 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)
|
||||
|
||||
Reference in New Issue
Block a user