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

[Request] Filter entries by given range? #57

Open
Ajaymamtora opened this issue Aug 11, 2024 · 3 comments
Open

[Request] Filter entries by given range? #57

Ajaymamtora opened this issue Aug 11, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Ajaymamtora
Copy link

Ajaymamtora commented Aug 11, 2024

Could we add an option to filter the picker entries by a given range?

For example we could bind in visual selection to take the start and end lines, and pass that into telescope-undo, then filter entries if they don't have a diff between the given lines? I used this a lot in IntelliJ and it would be useful to have here. It probably doesnt have to be smart and try and resolve where code has moved about between diffs, could probably just check the diff lies between the given line numbers

Maybe something like this before passing it into telescope:

local function undo_history_for_range(startline, endline)
    local undotree = vim.fn.undotree()
    local changes = {}

    for _, entry in ipairs(undotree.entries) do
        for _, change in ipairs(entry.changes or {}) do
            if change.new_start >= startline and change.old_end <= endline then
                table.insert(changes, change)
            end
        end
    end

    return changes
end

-- Example usage: Get undo history for lines 10 to 20
local changes = undo_history_for_range(10, 20)
print(vim.inspect(changes))

https://www.jetbrains.com/help/idea/local-history.html

@debugloop
Copy link
Owner

Hi, that's an interesting one. In principle this plugin just uses the builtin undo states which does not support any kind of querying based on content. However, we precalculate all diffs while visiting the undo states and building the tree, so we could tell which lines are affected with a minimum of fancy code necessary 🤔 What do you think about the following:

  1. If you restore a state shown by this _for_range function, you will still get any intermediate changes not shown. Yank maps will work nicely though.
  2. The tree view will be broken and not really fixable without a lot of effort.

Otherwise, this might be very doable and useful, yeah 👍🏻

@debugloop debugloop added the enhancement New feature or request label Aug 13, 2024
@Ajaymamtora
Copy link
Author

Ah okay, I personally wouldnt mind it because like you said theres always the option to yank the changes 👍🏻. Also maybe any change can create a new undo state on-top of the tree? Not sure if that's possible.

Ajaymamtora added a commit to Ajaymamtora/telescope-undo.nvim that referenced this issue Aug 13, 2024
Ajaymamtora added a commit to Ajaymamtora/telescope-undo.nvim that referenced this issue Aug 13, 2024
@Ajaymamtora
Copy link
Author

I had a play and this seems to work in my very brief testing but thought you might want to use it as a base?

#58

Ajaymamtora added a commit to Ajaymamtora/telescope-undo.nvim that referenced this issue Aug 13, 2024
Ajaymamtora added a commit to Ajaymamtora/telescope-undo.nvim that referenced this issue Aug 13, 2024
Ajaymamtora added a commit to Ajaymamtora/telescope-undo.nvim that referenced this issue Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants