altsem / gitu

A TUI Git client inspired by Magit
MIT License
1.66k stars 87 forks source link

Keybind to navigate between section #145

Closed musjj closed 2 months ago

musjj commented 2 months ago

Is there a keybind to navigate between sections directly? Right now I'm working around it by collapsing then navigating up/down. But it'd be nice if there's a direct keybind for it.

For reference here are the keybind magit uses for section navigation: https://magit.vc/manual/magit/Section-Movement.html

altsem commented 2 months ago

I think there now is in the linked PR. :D

musjj commented 2 months ago

You're a machine 😆. Just tested it and it works well for me!

EDIT: Actually, it seems that when you're inside the section (e.g. a line in the recent commits) alt+{j,k} doesn't directly move you between sections.

altsem commented 2 months ago

I see. Magit actually behaves like this, but I too think i'd prefer if it skipped above to the section hmm.

musjj commented 2 months ago

I haven't used magit in years, but there's this from the manual I linked above:

p (magit-section-backward)

When not at the beginning of a section, then move to the beginning of the current section. At the beginning of a section, instead move to the beginning of the previous visible section.

It looks like that it's supposed to move to the beginning of the section :thinking:

altsem commented 2 months ago

Got my magit here started on the side just to compare. I'm not exactly sure which things are considered sections in Magit. In Gitu they're the expandable/collapsible lines (log entries are not).

I updated the branch so that it (unlike Magit) skips these with alt-j/k now, it seems like a no-brainer.

musjj commented 2 months ago

Thanks, tested it again and it works better now! But it looks that it still doesn't work in the staged/unstaged changes, is it intentional?

altsem commented 2 months ago

No probs! I'm not sure I understand. could you describe more in details? I think maybe one thing that might seem confusing is that it is a tree of sections.

0 Staged Changes             (section)
  1 modified src/main.rs     (section)
    2 @@ ... @@              (section)
      3 + test test          
  1 modified src/foobar.rs   (section)
    2 @@ ... @@...           (section)

So moving up from "modified src/foobar.rs" takes me to the above sibling section "modified src/main.rs".

musjj commented 2 months ago

Ah, that makes sense. I guess this is where this keybind in magit would be useful:

^ (magit-section-up)

Move to the beginning of the parent of the current section.

Could this be implemented too?

altsem commented 2 months ago

It shouldn't be too hard. From what I could tell from testing magit-section-up in Magit, it would move like this:

0 Staged Changes             <-+ ...to here
  1 modified src/main.rs       |
    2 @@ ... @@                |
      3 + test test            |
  1 modified src/foobar.rs   <-+ from here
    2 @@ ... @@...           

I also noticed it would go to the top of the file if at level 0.

0 On branch ...              <-+ ...to here
  Your branch is ...           |
                               |
0 Staged Changes             <-+ From here
  1 modified src/main.rs       
    2 @@ ... @@                
      3 + test test            
  1 modified src/foobar.rs     
    2 @@ ... @@...

I'm considering whether ^ should be the hotkey for this. Could perhaps put it on alt+left / alt+h? Or all of them, something else?

altsem commented 2 months ago

@musjj I renamed these:

Think it's ready to go. Leaving it for a bit in case you have some input!

musjj commented 2 months ago

Works perfectly for me :+1: