Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(action): Allow passing a range to filter the undo items by lines (#57) #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ajaymamtora
Copy link

No description provided.

@Ajaymamtora Ajaymamtora changed the title feat(action): Allow passing a range to filter the undo items by ? #57 feat(action): Allow passing a range to filter the undo items by lines #57 Aug 13, 2024
@Ajaymamtora Ajaymamtora changed the title feat(action): Allow passing a range to filter the undo items by lines #57 feat(action): Allow passing a range to filter the undo items by lines (#57) Aug 13, 2024
Copy link
Owner

@debugloop debugloop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working great, thanks a lot for your contribution 🎉

Would you mind adding the new functionality to the README as well (config and default)? Assuming you have done that in your config, feel free to add an example mapping for this as well. I bet you're doing something cool, using the range from visual selection maybe? 😁

@Ajaymamtora
Copy link
Author

Ajaymamtora commented Sep 7, 2024

Hey no worries @debugloop , yep I'll do that. For some reason I cant find a clean way to do a keymap that reliably passes in the boundaries of the visual selection into telescope, this works but seems overkill:

    vim.api.nvim_create_user_command("TelescopeUndoVisual", function()
      -- Save the current view
      local view = vim.fn.winsaveview()

      -- Save the current mode
      local mode = vim.fn.mode()

      -- Temporarily switch to normal mode to ensure correct range capture
      vim.cmd("normal! \27")

      -- Get the first and last line numbers of the visual selection
      local start_line = vim.fn.line("'<")
      local end_line = vim.fn.line("'>")

      -- Call the function with the line range
      require("telescope").extensions.undo.undo({
        get_previewer = get_previewer,
        line_range = { start_line, end_line },
      })

      -- Restore the original view
      vim.fn.winrestview(view)

      -- If we were in visual mode, reselect the previous selection
      if mode == "v" or mode == "V" or mode == "\22" then
        vim.cmd("normal! gv")
      end
    end, { range = true })

Also nothing crazy just checking line numbers like I mentioned in the issue I raised haha

It should just be as simple as

      local start_line = vim.fn.line("'<")
      local end_line = vim.fn.line("'>")

then pass these in but for some reason they return 0 when used in a keymap? it works perfectly fine if I manually enter it while in a visual selection. Have you got any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants