-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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? 😁
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? |
Sorry, been on vacation and whatnot :) It's probably because this is referring to the telescope buffer then. I've got no idea for a fix though 🤔 Let's maybe leave it at those README additions, someone will figure it out in time and hopefully contribute :) |
No worries, Ive been using this and it has worked fine: local function open_undo_ts(args)
require("telescope").extensions.undo.undo({
get_previewer = get_previewer,
line_range = args.line_range,
})
end
vim.api.nvim_create_user_command("TelescopeUndo", function()
open_undo_ts({})
end, {})
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 }) But like you said lets just leave something in the readme :) |
No description provided.