Git Product home page Git Product logo

Comments (10)

debugloop avatar debugloop commented on July 22, 2024 3

The additional defaults are in now, I also added some general clarifications on configuring, mapping, and so on. Hope it helps, thanks for your feedback 🥇

from telescope-undo.nvim.

debugloop avatar debugloop commented on July 22, 2024 2

Hi, yes indeed <c-cr> and <s-cr> are kinda known to cause problems in various terminal emulators, especially with a multiplexer in the mix. Tbh, I mostly use normal mode with the undo telescope... I think I'll adopt yours as an additional default for insert mode in a future version 👍🏻

from telescope-undo.nvim.

freddiehaddad avatar freddiehaddad commented on July 22, 2024

FWIW: I changed the default mappings to:

i = {
    ['<cr>'] = function(...) return require('telescope-undo.actions').yank_additions(...) end,
    ['<c-y>'] = function(...) return require('telescope-undo.actions').yank_deletions(...) end,
    ['<c-r>'] = function(...) return require('telescope-undo.actions').restore(...) end,
 },
 n = {
    ['y'] = function(...) return require('telescope-undo.actions').yank_additions(...) end,
    ['Y'] = function(...) return require('telescope-undo.actions').yank_deletions(...) end,
    ['r'] = function(...) return require('telescope-undo.actions').restore(...) end,
},

Now things are are working as expected. It seems the Ctrl+Enter and Shift+Enter keymaps aren't working for me.

from telescope-undo.nvim.

freddiehaddad avatar freddiehaddad commented on July 22, 2024

Attaching my Telescope config in lazy.nvim for convenience:

return {
	{
		'nvim-telescope/telescope.nvim',
		dependencies = { { 'nvim-lua/plenary.nvim' }, { 'EdenEast/nightfox.nvim' } },
		init = function()
			local hl = vim.api.nvim_set_hl
			local p = require('nightfox.palette').load('carbonfox')

			hl(0, 'TelescopePreviewBorder', { fg = p.blue.dim })
			hl(0, 'TelescopePreviewTitle', { fg = p.blue.base })

			hl(0, 'TelescopePromptBorder', { fg = p.cyan.dim })
			hl(0, 'TelescopePromptTitle', { fg = p.cyan.bright })

			hl(0, 'TelescopeResultsBorder', { fg = p.orange.dim })
			hl(0, 'TelescopeResultsTitle', { fg = p.orange.bright })
		end,
		keys = {
			-- f
			{
				'<leader>ff',
				function() require('telescope.builtin').find_files() end,
				desc = 'Find files',
			},
			{
				'<leader>fF',
				function() require('telescope.builtin').find_files({ hidden = true, no_ignore = true }) end,
				desc = 'Find files (hidden)',
			},
			{
				'<leader>fb',
				function() require('telescope.builtin').buffers({ ignore_current_buffer = true, sort_mru = true }) end,
				desc = 'Find buffers',
			},

			-- s
			{
				'<leader>sb',
				function() require('telescope.builtin').current_buffer_fuzzy_find() end,
				desc = 'Search buffer',
			},
			{
				'<leader>sg',
				function() require('telescope.builtin').live_grep() end,
				desc = 'Grep files',
			},
			{
				'<leader>sG',
				function() require('telescope.builtin').live_grep({ grep_open_files = true }) end,
				desc = 'Grep files (Open files)',
			},
			{
				'<leader>sh',
				function() require('telescope.builtin').help_tags() end,
				desc = 'Search help tags',
			},
			{
				'<leader>sH',
				function() require('telescope.builtin').highlights() end,
				desc = 'Search highlights',
			},
			{
				'<leader>sw',
				function() require('telescope.builtin').grep_string({ word_match = '-w' }) end,
				desc = 'Search word',
			},
			{
				'<leader>sw',
				function() require('telescope.builtin').grep_string({ word_match = '-w' }) end,
				mode = 'v',
				desc = 'Search selection',
			},

			{
				'<leader>R',
				function() require('telescope.builtin').resume() end,
				desc = 'Resume',
			},
		},
		opts = {
			defaults = {
				-- use square corners
				borderchars = { '', '', '', '', '', '', '', '' },
			},
		},
	},

	-- native fuzzy search for telescope
	{
		'nvim-telescope/telescope-fzf-native.nvim',
		build = 'make',
		dependencies = {
			'nvim-telescope/telescope.nvim',
			opts = { extensions = { fzf = {} } },
		},
		init = function() require('telescope').load_extension('fzf') end,
	},

	-- telescope undo extension
	{
		'debugloop/telescope-undo.nvim',
		dependencies = {
			'nvim-telescope/telescope.nvim',
			opts = {
				extensions = {
					undo = {
						use_delta = false,
						layout_config = {
							preview_width = 0.75,
						},
						mappings = {
							i = {
								['<cr>'] = function(...) return require('telescope-undo.actions').yank_additions(...) end,
								['<c-y>'] = function(...) return require('telescope-undo.actions').yank_deletions(...) end,
								['<c-r>'] = function(...) return require('telescope-undo.actions').restore(...) end,
							},
							n = {
								['y'] = function(...) return require('telescope-undo.actions').yank_additions(...) end,
								['Y'] = function(...) return require('telescope-undo.actions').yank_deletions(...) end,
								['r'] = function(...) return require('telescope-undo.actions').restore(...) end,
							},
						},
					},
				},
			},
		},
		init = function() require('telescope').load_extension('undo') end,
		keys = {
			{ '<leader>su', function() require('telescope').extensions.undo.undo() end, desc = 'Search undo history' },
		},
	},
}

from telescope-undo.nvim.

haizaar avatar haizaar commented on July 22, 2024

Hitting this issue as well - out of the default mappings only <cr> is working. Somehow @freddiehaddad's workaround doesn't work for me.

My config is here (loading via NvChad): https://github.com/zarmory/NvChad/blob/v2.0/lua/custom/plugins.lua#L51

The plugin is still useful (thank you!), just not as useful as it could've been.

from telescope-undo.nvim.

freddiehaddad avatar freddiehaddad commented on July 22, 2024

@haizaar Can you post your config with the key map changes as well? I'm curious as to why my suggested modifications aren't working. It's either not being configured correctly or conflicting key maps.

If you notice in my example, I'm setting telescope as a dependency of the undo extension. This way I configured the key maps in telescope prior to loading the extension which I'm fairly sure is necessary.

from telescope-undo.nvim.

debugloop avatar debugloop commented on July 22, 2024

@freddiehaddad is right, the way Telescope works you'll always have to set telescope as a dependency. The other trick is to realize that you can call Telescope's setup as often as you'd like, it will merge configs (including additional keymaps) from consecutive calls. The second thing is, you wont be able to set keymaps in Lazy's opts field, as the require is likely not available yet due to lazy loading of some form (you could get that right, but...), so you best do that from config.

Looking at your config, you're never calling load_extension which telescope requires you to do.

I suggest doing this in addition to whatever you use as a standalone telescope plugin spec:

{
  "debugloop/telescope-undo.nvim",
  dependencies = {
    {
      "nvim-telescope/telescope.nvim",
      dependencies = {
        { "nvim-lua/plenary.nvim" },
      },
    },
  },
  keys = {
    {
      "<leader>u",
      "<cmd>Telescope undo<cr>",
      desc = "undo history",
    },
  },
  opts = {
    extensions = {
      undo = {
        side_by_side = true,
        layout_strategy = "vertical",
        layout_config = {
          preview_height = 0.8,
        },
      },
    },
  },
  config = function(_, opts)
    opts.defaults.mappings = {
      i = {
        ['<c-y>'] = require('telescope-undo.actions').yank_deletions,
        ['<c-r>'] = require('telescope-undo.actions').restore,
      },
    }
    require("telescope").setup(opts)
    require("telescope").load_extension("undo")
  end,
}

I'll put the two keymaps in asap, I should have never assumed proper handling of keycodes in people's terminals 🙃

from telescope-undo.nvim.

haizaar avatar haizaar commented on July 22, 2024

Thanks for the quick response. Looks like the opts table doesn't have defaults member:

Failed to run `config` for telescope-undo.nvim                                                                                                                                                                                                                                  
/home/.../.config/nvim/lua/custom/plugins.lua:96: attempt to index field 'defaults' (a nil value)
# stacktrace:
  - lua/custom/plugins.lua:96 _in_ **config**
  - /telescope.nvim/lua/telescope/_extensions/init.lua:8 _in_ **load_extension**
  - /telescope.nvim/lua/telescope/_extensions/init.lua:62
  - /telescope.nvim/lua/telescope/command.lua:197 _in_ **run_command**
  - /telescope.nvim/lua/telescope/command.lua:259 _in_ **load_command**
  - /telescope.nvim/plugin/telescope.lua:108

My config is here: zarmory/NvChad@fa9bb4a

from telescope-undo.nvim.

haizaar avatar haizaar commented on July 22, 2024

After removing the mapping definitions, it all works fine (since they are now defaults - thank you for adding those).

P.S. Telescope itself is initialized by NvChad here, in case it's related.

from telescope-undo.nvim.

debugloop avatar debugloop commented on July 22, 2024

Yup, makes sense, I've actually had a small error in above snippet (the assignment should not have been to default). If you keep to the readme it should work alright 👍

from telescope-undo.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.