feat: pasting image within buffer (#331)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham
2024-08-28 14:43:14 -04:00
committed by GitHub
parent 46a621e9de
commit c635f73748
12 changed files with 166 additions and 295 deletions

26
after/plugin/avante.lua Normal file
View File

@@ -0,0 +1,26 @@
--- NOTE: We will override vim.paste if img-clip.nvim is available to work with avante.nvim internal logic paste
local Clipboard = require("avante.clipboard")
local Config = require("avante.config")
if Config.support_paste_image() then
vim.paste = (function(overriden)
---@param lines string[]
---@param phase -1|1|2|3
return function(lines, phase)
local bufnr = vim.api.nvim_get_current_buf()
local filetype = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
if filetype ~= "AvanteInput" then
return overriden(lines, phase)
end
---@type string
local line = lines[1]
local ok = Clipboard.paste_image(line)
if not ok then
return overriden(lines, phase)
end
end
end)(vim.paste)
end