mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
fix(prompt): allow cancelling title input
This commit is contained in:
@@ -20,6 +20,7 @@ local linkutils = require("taglinks.linkutils")
|
|||||||
local dateutils = require("taglinks.dateutils")
|
local dateutils = require("taglinks.dateutils")
|
||||||
local Path = require("plenary.path")
|
local Path = require("plenary.path")
|
||||||
local vaultPicker = require("vaultpicker")
|
local vaultPicker = require("vaultpicker")
|
||||||
|
local tkutils = require("telekasten.utils")
|
||||||
|
|
||||||
-- declare locals for the nvim api stuff to avoid more lsp warnings
|
-- declare locals for the nvim api stuff to avoid more lsp warnings
|
||||||
local vim = vim
|
local vim = vim
|
||||||
@@ -2038,7 +2039,7 @@ local function CreateNoteSelectTemplate(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.ui.input({ prompt = "Title: " }, function(title)
|
tkutils.prompt_title(function(title)
|
||||||
if not title then
|
if not title then
|
||||||
title = ""
|
title = ""
|
||||||
end
|
end
|
||||||
@@ -2115,7 +2116,7 @@ local function CreateNote(opts)
|
|||||||
return CreateNoteSelectTemplate(opts)
|
return CreateNoteSelectTemplate(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.ui.input({ prompt = "Title: ", default = "" }, function(title)
|
tkutils.prompt_title(function(title)
|
||||||
if not title then
|
if not title then
|
||||||
title = ""
|
title = ""
|
||||||
end
|
end
|
||||||
|
|||||||
21
lua/telekasten/utils.lua
Normal file
21
lua/telekasten/utils.lua
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.prompt_title(callback)
|
||||||
|
local canceledStr = "__INPUT_CANCELLED__"
|
||||||
|
|
||||||
|
vim.ui.input({
|
||||||
|
prompt = "Title: ",
|
||||||
|
default = "",
|
||||||
|
cancelreturn = canceledStr,
|
||||||
|
}, function(title)
|
||||||
|
if title == canceledStr then
|
||||||
|
vim.cmd("echohl WarningMsg")
|
||||||
|
vim.cmd("echomsg 'Note creation cancelled!'")
|
||||||
|
vim.cmd("echohl None")
|
||||||
|
else
|
||||||
|
callback(title)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
Reference in New Issue
Block a user