avante.nvim icon indicating copy to clipboard operation
avante.nvim copied to clipboard

feature: clear diff mappings when diff is done

Open apa512 opened this issue 1 year ago • 6 comments

Feature request

When entering Avante's diff window a few mappings starting with c get added. My issue is that these mappings persist even as the diff is done, making common core bindings such as cc or ct_ unavailable. To clear them, I have to open another file and then go back to the original file.

It would be better if this could somehow be cleared as soon as the diff is done.

Motivation

It would save time and avoid annoyance as my regularly used keybindings don't work unless I remember to switch files.

Other

I could potentially help although I'm not familiar with Lua or Neovim internals.

apa512 avatar Sep 12 '24 01:09 apa512

we already clear the mapping once all conflicts are resolved?

https://github.com/yetone/avante.nvim/blob/f9520c4fdfed08e9cc609d6cd319b358e4ea33a5/lua/avante/diff.lua#L400

can you provide a reproducer?

aarnphm avatar Sep 15 '24 15:09 aarnphm

Sure. I stripped my vim config down to only include avante and I'm still having the same issue. Here's the config:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out, "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

vim.g.mapleader = ','
vim.g.maplocalleader = ','

require("lazy").setup({
  spec = {
    {
      'yetone/avante.nvim',
      event = 'Lazy',
      lazy = false,
      opts = {
        hints = {
          enabled = false
        },
        windows = {
          width = 50
        }
      },
      build = ':AvanteBuild',
      dependencies = {
        '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',
          dependencies = {
            {
              'nvim-treesitter/nvim-treesitter',
              build = ":TSUpdate",
              config = function () 
                local configs = require("nvim-treesitter.configs")

                configs.setup({
                  ensure_installed = { "c", "lua", "vim", "ruby", "vimdoc", "query", "elixir", "json", "heex", "javascript", "html", "typescript", "tsx" },
                  sync_install = false,
                  highlight = { enable = true },
                  indent = { enable = true },
                })
              end
            }
          },
          opts = {
            file_types = { 'markdown', 'Avante' },
          },
          ft = { 'markdown', 'Avante' },
        },
      },
    },
  },
  checker = { enabled = false },
})

The steps outlined above results in the diff being done but with cc and other keys still being mapped to avante diff commands, confirmed by

  1. looking at :map
  2. trying cc and notice that it doesn't do anything

apa512 avatar Sep 20 '24 09:09 apa512

after diff is finished, cc is still binded?

aarnphm avatar Sep 20 '24 20:09 aarnphm

The same issue occurred to me. Even after the diff is completed, the cc command is still bound until I close the buffer

Ja-sonYun avatar Nov 29 '24 15:11 Ja-sonYun

https://github.com/yetone/avante.nvim/blob/f9520c4fdfed08e9cc609d6cd319b358e4ea33a5/lua/avante/diff.lua#L377 In my case, when execute the line vim.fn.hasmapto(mapping, “n”), it returns an empty value(possibly nil), which causes it to skip deleting the keymaps.

Also I couldn’t find the code to unbind the “v” keymaps in diff.lua, so the diff keymap won’t be completely removed.

Isn’t it better to dump the previous keymaps to somewhere, resolve the conflict, and then restore the keymaps from that dump?

Ja-sonYun avatar Nov 29 '24 16:11 Ja-sonYun

Same issue here. It would be nice if cc restores to its original function after resolving the diff.

LAST7 avatar Jan 16 '25 14:01 LAST7

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 06 '25 02:10 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Oct 12 '25 02:10 github-actions[bot]