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

🚀 Keybinding to jump between files in navigate mode #680

Closed
tjkirch opened this issue Aug 10, 2021 · 4 comments · Fixed by #684
Closed

🚀 Keybinding to jump between files in navigate mode #680

tjkirch opened this issue Aug 10, 2021 · 4 comments · Fixed by #684

Comments

@tjkirch
Copy link

tjkirch commented Aug 10, 2021

Would it be possible to add additional keybindings that jump to the next or previous file in a diff? Some files have many diff hunks (such as generated files, like Cargo.lock in Rust) and it'd be nice to be able to skip down to the next file.

I see that the keybindings for navigating hunks insert a search pattern in less's history, and I don't see a way for less to have multiple patterns or keybindings, so I couldn't personally see a way without switching pager.

@dandavison
Copy link
Owner

Hi @tjkirch! I think you're right -- it looks like we need to expose a bit more control over the details of the navigate regexp. E.g. unmerged commit dfc149c gives us distinct labels for file and hunk boundaries, but we also need to give users the ability to alter the regex itself that delta seeds less with, in order to specify stopping on file boundaries only.

@ghost
Copy link

ghost commented Aug 12, 2021

@dandavison I think it's also worth thinking about the order of the labels in the regex.
If we have

^(commit|added:|removed:|renamed:|Δ|δ)

(the hunk label is last), it will be easy to switch to jumping by files by pressing /, Up, and removing the last couple of chars and pressing Enter.

@dandavison
Copy link
Owner

Nice @lepotic. Thanks very much for that suggestion. I've made your change and opened PR #684. I'm thinking that gives us a pretty workable solution; @tjkirch @lepotic what do you think? #684 PR description copied below:


Fixes #680 cc @tjkirch @lepotic

This changes the labels that delta adds when navigate = true: we now have an upper-case delta on file boundaries, and a lower-case delta on hunk boundaries:

image

As suggested by @lepotic #680 (comment), this allows us to switch to navigating by file with / <up> <left> <backspace> <backspace> <enter>.

In other words, using / <up> to reveal the current search regex:

/^(commit|added:|removed:|renamed:|Δ|δ)

and then editing this to remove the lower-case delta:

/^(commit|added:|removed:|renamed:|Δ)

and finally resuming search with <enter>.

The labels can be modified. E.g.

[delta]
    file-modified-label = @
    hunk-label = *

(and it is ok to use something like * which has special meaning in regular expressions).

dandavison added a commit that referenced this issue Aug 21, 2021
* Use distinct navigate label for file and hunk boundaries

Ref #680

* Make it easy to remove hunk label from navigate regex

Thanks @lepotic for the suggestion.
Fixes #680

* Allow regex meta characters to be used in navigate anchors
@dandavison
Copy link
Owner

Released in 0.9.0 (I changed the default value of hunk-label to a bullet rather than a lowercase delta)

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 a pull request may close this issue.

2 participants