zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
20.47k stars 637 forks source link

`zellij move-focus-or-tab` `up`/`down` does not behave as expected but `left`/`right` does #3239

Closed xav-ie closed 5 months ago

xav-ie commented 5 months ago

Issues with the Zellij UI / behavior / crash

Issue description

As explained in https://zellij.dev/documentation/cli-actions#move-focus-or-tab , you can navigate as if you are going to navigate panes in any direction until you reach an edge. This works for left and right, first preferring pane movements, then switching to tab movement when on an edge. This does not do pane movements for up/down, it always switches tabs.

I think this might be intended behavior? Or maybe it was just forgotten to be implemented? Here is the source of the problem: https://github.com/zellij-org/zellij/blob/d267948689a30a276adbe9e7cedf2be792d15b73/zellij-server/src/route.rs#L140-L145

It is clear to see here that you will never get the desired behavior and there is not bug in pane edge detection or something, it is just switching tabs.

Minimal reproduction

For left/right movement, this works well. Say you start with 3x3 grid of panes and start in middle:

|---------------------|
|      |       |      |
|      |       |      |
|______|_______|______|
|      | start |      |
|      | here* |      |
|______|_______|______|
|      |       |      |
|      |       |      |
|---------------------|
| tab 1* | tab 2  |   |
|---------------------|

Calling zellij move-focus-or-tab right moves you right one pane:

|---------------------|
|      |       |      |
|      |       |      |
|______|_______|______|
|      |       | here*|
|      |       |      |
|______|_______|______|
|      |       |      |
|      |       |      |
|---------------------|
| tab 1* | tab 2  |   |
|---------------------|

This also works the same with zellij move-focus right. Calling zellij move-focus-or-tab right again, we move onto tab 2 (it has same layout as tab 1):

|---------------------|
| *    |       |      |
|      |       |      |
|______|_______|______|
|      |       |      |
|      |       |      |
|______|_______|______|
|      |       |      |
|      |       |      |
|---------------------|
| tab 1  | tab 2* |   |
|---------------------|

This is expected! We can also move down panes with zellij action move-focus down:

|---------------------|
|      |       |      |
|      |       |      |
|______|_______|______|
| *    |       |      |
|      |       |      |
|______|_______|______|
|      |       |      |
|      |       |      |
|---------------------|
| tab 1  | tab 2* |   |
|---------------------|

If we rewind, and call zellij action move-focus-or-tab down, we get a different result :(, the next "down" tab is selected:

|---------------------|
|      |       |      |
|      |       |      |
|______|_______|______|
|      |       | *    |
|      |       |      |
|______|_______|______|
|      |       |      |
|      |       |      |
|---------------------|
| tab 1* | tab 2  |   |
|---------------------|

zellij 0.39.2

Happy and interested to make a PR with tests, but I am not sure if this is what is expected/wanted by you.

jaeheonji commented 5 months ago

As I know, I understand that this is an intended behavior.

The user can intuitively understand the focus up and down in the grid pan, but in the case of Tab, it always moves only horizontally.

For example, if the focus continues to move down and when it reaches the end, the cursor then moves to the next tab, the change in direction becomes strange.

For this reason, Up / Down is understood to only include tab switching.

Also, looking at zellij's default settings, MoveFocusOrTab's Up/Down is not used.

Basically, all focus switching is possible with MoveTab and MoveFocus, and MoveFocusOrTab is close to a kind of convenience.

If you have better ideas for this, please create new issue with feature request or discussion!

Thank you and I hope you understand.

xav-ie commented 5 months ago

After thinking about this some more, I think this is actually not intentional.

Also, looking at zellij's default settings, MoveFocusOrTab's Up/Down is not used. Yes, I think it is because this feature was never implemented.

There is already a command to move tabs up and down. It is important to have this command.

Basically, all focus switching is possible with MoveTab and MoveFocus, and MoveFocusOrTab is close to a kind of convenience.

If you are saying MoveFocusOrTab Up/Down is a convenience, then I agree, but they should behave the same as left right. I was trying to find workarounds for this, but it is really not possible.

@jaeheonji , I think I know what needs to be changed to fix this, may I please make a PR to fix this?

jaeheonji commented 5 months ago

If you are saying MoveFocusOrTab Up/Down is a convenience, then I agree, but they should behave the same as left right. I was trying to find workarounds for this, but it is really not possible.

@jaeheonji , I think I know what needs to be changed to fix this, may I please make a PR to fix this?

I still don't think this is a bug, nor do I see it as a problem that needs to be fixed. Also, I don't think MoveFocusOrTab Up/Down should work the same as Left/Right.

I still think that moving the tab when focus is down is strange in terms of UX. Because in the entire code, Zellij Tab movement only moves to Left or Right and Prev/Next.

Rather, we can change Up and Down to Focus movement rather than Tab movement. But, This is a minor change and still not considered a bug, so it's low on priority.