From 62e6f9fd1e0cfb1f7dc80127c9e13e9fe8b82dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Harnes?= Date: Mon, 1 Apr 2024 14:04:17 +0200 Subject: [PATCH] fix: only add file extension if its missing --- lua/img-clip/fs.lua | 6 ++++-- lua/img-clip/paste.lua | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/img-clip/fs.lua b/lua/img-clip/fs.lua index 877dd50..f7e2a31 100644 --- a/lua/img-clip/fs.lua +++ b/lua/img-clip/fs.lua @@ -117,8 +117,10 @@ M.get_file_path = function(ext) file_path = dir_path .. config_file_name end - -- add file ext - file_path = M.add_file_ext(file_path, ext) + -- add file ext if missing + if vim.fn.fnamemodify(file_path, ":e") == "" then + file_path = M.add_file_ext(file_path, ext) + end return file_path end diff --git a/lua/img-clip/paste.lua b/lua/img-clip/paste.lua index db83aeb..f0ad7d3 100644 --- a/lua/img-clip/paste.lua +++ b/lua/img-clip/paste.lua @@ -48,6 +48,7 @@ end ---@param url string M.paste_image_from_url = function(url) + -- if we are not downloading images, then just insert the url if not config.get_opt("download_images") then if not markup.insert_markup(url) then util.error("Could not insert markup code.") @@ -103,6 +104,7 @@ M.paste_image_from_path = function(src_path) end end + -- if we are not copying images, then just insert the original path if not config.get_opt("copy_images") then if not markup.insert_markup(src_path, true) then util.error("Could not insert markup code.")