remotes/origin/HEAD
pseudometa 2022-12-12 11:19:34 +01:00
parent d51c3f7814
commit 15efe61d00
1 changed files with 4 additions and 5 deletions

View File

@ -1,7 +1,6 @@
local M = {} local M = {}
local logError = vim.log.levels.ERROR local logError = vim.log.levels.ERROR
local logWarn = vim.log.levels.WARN
local expand = vim.fn.expand local expand = vim.fn.expand
local fn = vim.fn local fn = vim.fn
local cmd = vim.cmd local cmd = vim.cmd
@ -42,7 +41,7 @@ local function fileOp(op)
prefill = "" prefill = ""
end end
vim.ui.input({prompt = promptStr, default = prefill}, function(newName) vim.ui.input({prompt = promptStr, default = prefill, complete= "filetype"}, function(newName)
local invalidName = false local invalidName = false
local sameName local sameName
if newName then if newName then
@ -51,13 +50,13 @@ local function fileOp(op)
end end
if not (newName) or invalidName or sameName then -- cancel if not (newName) or invalidName or sameName then -- cancel
if op == "newFromSel" then if op == "newFromSel" then
cmd [[undo]] -- undo deletion cmd.undo() -- undo deletion
fn.setreg("z", prevReg) -- restore register content fn.setreg("z", prevReg) -- restore register content
end end
if invalidName then if invalidName then
vim.notify(" Invalid filename. ", logError) vim.notify(" Invalid filename. ", logError)
elseif sameName then elseif sameName then
vim.notify(" Cannot use the same filename. ", logWarn) vim.notify(" Cannot use the same filename. ", logError)
end end
return return
end end
@ -66,7 +65,7 @@ local function fileOp(op)
if not (extProvided) then newName = newName .. oldExt end if not (extProvided) then newName = newName .. oldExt end
local filepath = dir .. "/" .. newName local filepath = dir .. "/" .. newName
cmd [[update]] -- save current file; needed for users with `vim.opt.hidden=false` cmd.update() -- save current file; needed for users with `vim.opt.hidden=false`
if op == "duplicate" then if op == "duplicate" then
cmd {cmd = "saveas", args = {filepath}} cmd {cmd = "saveas", args = {filepath}}
cmd {cmd = "edit", args = {filepath}} cmd {cmd = "edit", args = {filepath}}