avante.nvim/after/plugin/avante.lua
yetone d5a4db8321
Revert tokenizers (#423)
* Revert "fix: add missing "with" in README"

This reverts commit bf1e7f1f17c8b82687b15c41e5a8104ea03f70cf.

* Revert "feat: tokenizers (#407)"

This reverts commit d2095ba267abbfe169582708a4449e609aa9709b.
2024-08-31 22:45:31 +08:00

34 lines
1.1 KiB
Lua

--- 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(true) then
vim.paste = (function(overriden)
---@param lines string[]
---@param phase -1|1|2|3
return function(lines, phase)
require("img-clip.util").verbose = false
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
-- After pasting, insert a new line and set cursor to this line
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, { "" })
local last_line = vim.api.nvim_buf_line_count(bufnr)
vim.api.nvim_win_set_cursor(0, { last_line, 0 })
end
end)(vim.paste)
end