yetone/avante.nvim

bug: Cmd+V image paste not working in macOS input buffer

Opened this issue · 0 comments

Describe the bug

When using Avante in macOS, the Cmd+V shortcut for pasting images doesn't work in the input buffer, although regular text paste works in normal Neovim buffers.

To reproduce

  1. Install Avante on macOS
  2. Open Neovim and trigger Avante
  3. Copy an image to clipboard (e.g., from Screenshot or other apps)
  4. Try to paste the image using Cmd+V in Avante's input buffer
  5. The paste operation doesn't trigger any events in Avante

Expected behavior

Cmd+V should work for pasting images in Avante's input buffer, similar to how it works in other macOS applications.

Installation method

require("lazy").setup({
{
"yetone/avante.nvim",
dir = "~/loadrc/avante.nvim",
event = "VeryLazy",
lazy = false,
version = false,
opts = {},
config = function()
if setup_done then
return
end

  local ok, lib = pcall(require, 'avante_lib')
  if not ok then
    return
  end

  lib.load()

  ok, repo_map = pcall(require, "avante.repo_map")
  if not ok then
    return
  end

  if not repo_map.setup then
    repo_map.setup = function()
      return true
    end
  end

  vim.defer_fn(function()
    local ok, avante = pcall(require, 'avante')
    if not ok then
      return
    end

    if type(avante.setup) ~= "function" then
      return
    end

    ok, err = pcall(function()
      avante.setup({
        debug = true,
        provider = "claude",
        claude = {
          endpoint = "https://api.anthropic.com/v1",
          model = "claude-3-5-sonnet-20241022",
          timeout = 30000,
          temperature = 0,
          max_tokens = 4096,
          on_error = function(result)
            -- 直接打印错误信息
            if result.body then
              local ok, body = pcall(vim.json.decode, result.body)
              if ok and body and body.error then
                vim.notify(
                  "Claude API Error: " .. body.error.message,
                  vim.log.levels.ERROR,
                  { title = "Avante" }
                )
              end
            end
            -- 记录到日志
            vim.fn.writefile(
              {vim.fn.strftime("%Y-%m-%d %H:%M:%S") .. " Error: " .. vim.inspect(result)},
              vim.fn.stdpath("state") .. "/avante.log",
              "a"
            )
          end
        }
      })
    end)
    if ok then
      setup_done = true
    else
      print("Avante setup error:", err)
    end
  end, 100)
end,
dependencies = {
  "nvim-treesitter/nvim-treesitter",
  "stevearc/dressing.nvim",
  "nvim-lua/plenary.nvim",
  "MunifTanjim/nui.nvim",
  "nvim-tree/nvim-web-devicons",
  "zbirenbaum/copilot.lua",
  {
    "HakonHarnes/img-clip.nvim",
    event = "VeryLazy",
    opts = {
      default = {
        embed_image_as_base64 = false,
        prompt_for_file_name = false,
        drag_and_drop = {
          insert_mode = true,
        },
        use_absolute_path = true,
      },
    },
  },
  {
    'MeanderingProgrammer/render-markdown.nvim',
    opts = {
      file_types = { "markdown", "Avante" },
    },
    ft = { "markdown", "Avante" },
  },
},

},

Environment

  • neovim version: NVIM v0.11.0-dev-709+gb68511e295-dirty Build type: RelWithDebInfo LuaJIT 2.1.1720049189
  • platform: macOS

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    -- add any other plugins here
  },
})