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

tab_switch_strategy can act weird when closing tabs created with --keep-focus #4987

Closed
salmankhilji opened this issue Apr 18, 2022 · 5 comments
Labels

Comments

@salmankhilji
Copy link

Describe the bug
If I create tabs using the remote-control command @ launch --keep-focus, then closing each tab switches focus in a somewhat confusing order.

To Reproduce
Steps to reproduce the behavior:

  1. Launch kitty:
kitty --config NONE -o remember_window_size=no -o allow_remote_control=yes -o initial_window_width=90c bash --norc
  1. Create some tabs:
for i in {A..F}; do kitty @ launch --type=tab --tab-title=$i --keep-focus; done
  1. Repeatedly close all tabs using CTRL+SHIFT+w and observe the order of the focused tab at each step.

Observed Behavior

(The tab with focus is Bold.)

~ A B C D E F
A B C D E F
A B C D E
B C D E
B C D
C D
C

It looks like the focus alternates between the first and the last tab as I close each tab.

The issue here is with the meaning of previous when you do not really switch to a tab while creating it.

I'd say --keep-focus should act as if the user had switched to the tab, so that focused tab should be in the reverse creation order.

Environment details

kitty 0.25.0 (b569c01b49) created by Kovid Goyal
Linux byteevo 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64
Ubuntu 20.04.4 LTS byteevo /dev/tty

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"
Running under: X11
Frozen: False
Paths:
  kitty: /home/precor/Developer/kitty/kitty/launcher/kitty
  base dir: /home/precor/Developer/kitty
  extensions dir: /home/precor/Developer/kitty/kitty
  system shell: /bin/bash
Loaded config overrides:
  remember_window_size no
  allow_remote_control yes
  initial_window_width 90c

Config options different from defaults:
allow_remote_control y
initial_window_width (90, 'cells')
remember_window_size False

Important environment variables seen by the kitty process:
	PATH                                /home/precor/.nvm/versions/node/v14.18.2/bin:/opt/qt/5.15.2/gcc_64/bin:/home/precor/.local/flutter/bin:/home/precor/.pub-cache/bin:/home/precor/Android/Sdk/build-tools/30.0.3:/home/precor/Android/Sdk/emulator:/home/precor/Android/Sdk/platform-tools:/home/precor/Android/Sdk/cmdline-tools/latest/bin:/home/precor/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
	LANG                                en_US.UTF-8
	SHELL                               /bin/bash
	DISPLAY                             :0
	USER                                precor
	XDG_CONFIG_DIRS                     /etc/xdg/xdg-ubuntu:/etc/xdg
	XDG_MENU_PREFIX                     gnome-
	XDG_SESSION_DESKTOP                 ubuntu
	XDG_SESSION_TYPE                    x11
	XDG_CURRENT_DESKTOP                 ubuntu:GNOME
	XDG_SESSION_CLASS                   user
	XDG_RUNTIME_DIR                     /run/user/1000
	XDG_DATA_DIRS                       /usr/share/ubuntu:/usr/local/share/:/usr/share/

Additional context
Kitty is built from source master branch @ b569c01b.

I do not really need the fix in my workflow. However, just thought I'd file it anyway.

@salmankhilji
Copy link
Author

This is not completely fixed. If I CTRL+SHIFT+right a few times to select a tab, this briefly activates the ones that I went through and should, therefore, should prioritize these tabs in the closing order.

Please try:

  1. Launch kitty:

    kitty --config NONE -o remember_window_size=no -o allow_remote_control=yes -o initial_window_width=90c bash --norc
    
  2. Create some tabs:

    for i in {A..F}; do kitty @ launch --type=tab --tab-title=$i --keep-focus; done
    
  3. CTRL+SHIFT+right 3 times to switch to Tab C.

  4. Repeatedly close all tabs using CTRL+SHIFT+w and observe the order of the focused tab at each step.

Observed Behavior

~ A B C D E F
~ A B D E F
~ A D E F (wrong: should have been ~ A D E F since Tab A was briefly selected while we went through it to select Tab C.)

@kovidgoyal
Copy link
Owner

If you go through tabs they have been activated so they will show up in
previous order. That is working as expected.

@salmankhilji
Copy link
Author

Perhaps I am confused. Lets walk through the scenario:

When creating tabs A-F, if without visiting any other tab, I start closing them right away, just like in the original repro steps, the tabs get closed in this order: ~ A B C D E F. This means the MRU order is the reverse creation order. This is good—I like it.

Now the new scenario: I have tabs ~ A B C D E F. Switching to Tab C using CTRL+SHIFT+right 3 times gives me this MRU: C B A ~ D E F. However, kitty switches to Tab D instead of Tab A upon the second attempt.

I admit this is confusing. I have since set tab_switch_strategy to left within my kitty.conf file as this scenario only applies to when the user is directly switching to a non-adjacent tab using the mouse or some other keyboard shortcut. My personal muscle memory forces me to go through the intermediate tabs to switch to a different one, so in my case, left is good enough.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Apr 19, 2022 via email

@salmankhilji
Copy link
Author

salmankhilji commented Apr 20, 2022

Within my last posted repro steps, if after creating the new tabs and using CTRL+SHIFT+right 3 times to switch to Tab C, I create a new tab with --location=after and close that new tab, then kitty highlights the last tab, which is wrong. i.e.,

  1. Launch kitty:

    kitty --config NONE -o remember_window_size=no -o allow_remote_control=yes -o initial_window_width=90c bash --norc
    
  2. Create some tabs:

    for i in {A..F}; do kitty @ launch --type=tab --tab-title=$i --keep-focus; done
    
  3. CTRL+SHIFT+right 3 times to switch to Tab C.

  4. kitty @ launch --type=tab --location=after --tab-title ToBeClosed

  5. CTRL+SHIFT+w to close Tab ToBeClosed.

Observed Behavior

Tab F is selected.

Expected Behavior

Tab B is selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants