debugloop / telescope-undo.nvim

A telescope extension to view and search your undo tree 🌴
MIT License
635 stars 11 forks source link

Unable to map `<cr>` to `require("telescope-undo.actions").restore` when using lazy.nvim #29

Closed j-barnak closed 1 year ago

j-barnak commented 1 year ago

To preface, yank_additions, yank_deletions, and restore all work prior to editing mappings so I know the issue is not with my terminal.

Proof of telescope-undo working normally with \<C-cr> restoring the buffer

I have tried a variation of the following:

return {
  "nvim-telescope/telescope.nvim",
  dependencies = {
    "nvim-lua/plenary.nvim",
    {
      "nvim-telescope/telescope-fzf-native.nvim",
      build = "make",
    },
    "debugloop/telescope-undo.nvim",
  },
  keys = {
    {
      "<leader>fu",
      "<cmd>Telescope undo<cr>",
      desc = "View undos",
    },
  },
  opts = {
    extensions = {
      undo = {
        mappings = {
          i = {
            ["<S-cr>"] = require("telescope-undo.actions").yank_additions,
            ["<C-cr>"] = require("telescope-undo.actions").yank_deletions,
            ["<cr>"] = require("telescope-undo.actions").restore,
          },
        }
      }
    }
  },
  config = function()
    require("telescope").load_extension("undo")
  end,
}

which gives me this error:

Error detected while processing /home/franky/Projects/dotfiles/neovim/.config/nvim/init.lua:
Failed to load `plugins.telescope`
/home/franky/.config/nvim/lua/plugins/telescope.lua:55: module 'telescope-undo.actions' not found:

And so, I manually passed opts to config and called setup myself.

config = function(_, opts)
    require("telescope").load_extension("undo")
    require("telescope").setup(opts)
  end,

but I get the same error.

I wrapped my calls init callbacks with

opts = {
  extensions = {
    undo = {
      mappings = {
        i = {
          ["<S-cr>"] = function()
            require("telescope-undo.actions").yank_additions()
          end,

          ["<C-cr>"] = function()
            require("telescope-undo.actions").yank_deletions()
            end,

            ["<cr>"] = function()
            require("telescope-undo.actions").restore()
            end,
        },
        }
    }
    }
},
config = function(_, opts)
  require("telescope").setup(opts)
  require("telescope").load_extension("undo")
end,

And that causes telescope-undo not work in the telescope floating window. Every press of enter resets the cursor

Video showcase #1

---

Edit: I have also tried the following, but this still doesn't work. I decided to include it because I'm not sure if this is *progress*. Pressing enter on on an undo item opens a blank screen (video example below)

opts = {
  extensions = {
    undo = {
      mappings = {
        ["<s-cr>"] = function()
          require("telescope-undo.actions").yank_additions()
        end,
        ["<c-cr>"] = function()
          require("telescope-undo.actions").yank_deletions()
        end,
        ["<cr>"] = function()
          require("telescope-undo.actions").restore()
        end,
      },
    },
  },
},
config = function(_, opts)
  require("telescope").setup(opts)
  require("telescope").load_extension("undo")
end,

Video showcase #2

I removed the opts and did everything in the config.

config = function()
  require("telescope").load_extension("undo")

  local opts = {
    extensions = {
      undo = {
        mappings = {
          ["<s-cr>"] = require("telescope-undo.actions").yank_additions,
          ["<c-cr>"] = require("telescope-undo.actions").yank_deletions,
          ["<cr>"] = require("telescope-undo.actions").restore
        },
      },
    },
  }

  require("telescope").setup(opts)
end,

And putting the setup before the load_extension

config = function()
  local opts = {
    extensions = {
      undo = {
        mappings = {
          ["<s-cr>"] = require("telescope-undo.actions").yank_additions,
          ["<c-cr>"] = require("telescope-undo.actions").yank_deletions,
          ["<cr>"] = require("telescope-undo.actions").restore
        },
      },
    },
  }

  require("telescope").setup(opts)
  require("telescope").load_extension("undo")
end,

Putting the setup after the load_extensions does nothing

Here's what happens before setup is before the load_extensions

j-barnak commented 1 year ago

Here's how'd you do it

return {
  "nvim-telescope/telescope.nvim",
  dependencies = {
    "nvim-lua/plenary.nvim",
    "debugloop/telescope-undo.nvim",
  },
  config = function()
    local opts = {
      extensions = {
        undo = {
          mappings = {
            i = {
              ["<s-cr>"] = require("telescope-undo.actions").yank_additions,
              ["<c-cr>"] = require("telescope-undo.actions").yank_deletions,
              ["<cr>"] = require("telescope-undo.actions").restore
            },
          },
        },
      },
    }

    require("telescope").setup(opts)
    require("telescope").load_extension("undo")
  end,
}

Was forgetting the i under mapping