-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
Creating a new empty editor group can leave focus in inactive group #189256
Comments
Please diagnose the root cause of the issue by running the command Happy Coding! |
I ran the issue troubleshooter, including installing and replicating the issue inside of VS Code - Insiders. After all that, it gave me a popup to create a new issue (which, just like the first time I tried to report this, does absolutely nothing when you click "Create on GitHub"): ...Do I need to add something from this window to this issue? What does the Triage Bot mean by "update the issue with the results?" Hopefully it'll recognize this reply as my update. Like I said, clicking "Create on GitHub" does nothing, so here's all the stuff from those three checkboxes, manually copied over: System information
Enabled extensions (0)Extensions: noneA/B experiment info
|
@matthew-e-brown kudos, excellent finding and very good issue description. I can reproduce the issue but it does not seem like a recent regression. When debugging this, I can see how
I think the cause is a call to vscode/src/vs/base/browser/ui/grid/gridview.ts Line 1090 in 51aefd9
This probably removes and adds the grid from the DOM, thus focus is lost. I think this operation would have to remember and restore the Irrespective, I am actually wondering why the commands to create new editor groups would not focus the new group, that is maybe something I could change, but it might also break existing assumptions of our users... |
workbench.action.newGroup*
commands do not handle focus correctly in some circumstancesactiveElement
to get lost
Looking more into this, I see how I already accommodate for this issue in some parts of the code, for example here: vscode/src/vs/workbench/browser/parts/editor/editorPart.ts Lines 723 to 727 in be900a4
I am pushing a change to do the same for Leaving this still open to consider for grid. |
Decided to push a fix that the commands to create editor groups ( |
I am not 100% sure my fix is good. Forcing keyboard focus into the new group is a somewhat breaking change for muscle memory. For example, you might have keyboard focus in a tree/list, want to create a new empty group and then decide to open an item from the tree/list in it. This is no longer possible if we forcefully move focus to the new empty group. |
@matthew-e-brown Looking more into this, this is actually working as intended (but I am thinking we can tweak this - more at the end) with 1 slight bug: in some cases, opening an editor group will result in an operation that removes the current editor group from the DOM and adds it back. If that editor group had keyboard focus, focus will move to the The bug here is that we loose focus to the The somewhat weird part here is that you see an inactive group that has keyboard focus. You cannot really get into this state unless you follow the steps in this issue. I wonder if the fix needs to be clever:
Does that sound reasonable? |
activeElement
to get lost
@bpasero Your fix seems perfectly reasonable :) I was a bit confused what the difference was between "an editor having focus" and "an active editor" were, but your explorer example cleared it up. It feels a bit silly to admit, but I honestly never considered a scenario where you'd have focus in a non-editor panel and attempt to use these commands. Now that I'm thinking about it, it only makes sense that "below" would be "below the one you were using before you jumped to the explorer"---at which point, I think it would only make sense for focus to remain where it was.
I wonder if perhaps it would make sense to use two (sets of) commands;
Something like that would keep the default (moving focus into the new group) for most people, but allow those who have muscle memory for the other behaviour use a different command if it suits their workflow better. It's a pretty niche market to warrant adding a whole new command for, but... just a thought. 🙂 |
Yeah thanks for the suggestion but I think the way it works now is OK for the future. I cannot really envision that someone would want to create a new group without also activating it. I actually think - because of this bug where focus would move to the |
This bug has been fixed in the latest release of VS Code Insiders! @matthew-e-brown, you can help us out by commenting If things still don't seem right, please ensure you're on version e073d67 of Insiders (today's or later - you can use Happy Coding! |
Information
Yes.
Expected behaviour
Explicitly creating a new group above, below, to the right, or to the left of the current group should always behave the same. With regards to focus, I expect that the new, empty group should receive focus right away. This means that commands like Go to File... (
CTRL+P
) or File: New Untitled Text File (CTRL+N
) should open and create files in the new group.As intuition would imply, the new group receiving focus should disable text input in the previous editor. From there, it stands to reason that using
workbench.action.focus(Above|Below|Left|Right)Group
should be able to move focus back to the original group, or to any other groups relative to the new one.Actual behaviour
When creating a new group, there are certain scenarios (detailed below) in which the new editor does not properly receive focus. Instead, VS Code enters a strange state where focus appears to be both on the new editor group and in the previous editor at the same time. This breaks a few things in odd ways:
CTRL+N
correctly creates a blank plain-text editor in the new group;CTRL+P
opens a new file in the previous group, where the text focus is.CTRL+ALT+↑/↓
to create multi-cursors, and so on.CTRL+S
does nothing.focus*Group
commands work relative to the currently focused group, and the group focus is updated correctly, getting text focus into the new group cannot be done with a simplefocus*Group
command. For example,newGroupRight
followed byfocusRightGroup
does nothing, unless that new group has something further to the right of it, in which case text focus will move all the way to the third group.Steps to reproduce
I have done more than an hour of testing, and still cannot track down the exact circumstances under which this bug occurs. It seems to depend on a number of layout-related factors.
newGroupLeft
andnewGroupRight
vs.newGroupAbove
andnewGroupBelow
).workbench.editor.closeEmptyGroups
setting does not seem to affect this behaviour.Below is a series of steps to reproducibly demonstrate the above points. Although I just mentioned that
closeEmptyGroups
does not affect the behaviour, these steps should be followed with it set totrue
in order to get identical results.CTRL+P
).CTRL+P
or by double clicking on it in the explorer. It should be in what is currently the only editor in the only group.CTRL+P
orCTRL+N
).CTRL+W
).CTRL+P
).CTRL+W
).CTRL+P
to open a file in this new editor.CTRL+P
will open a file in the third group, leaving the fourth empty, butCTRL+N
will open a blank plain-text file in the fourth group.Screen recording
2023-07-30_00-21-02.mp4
Keyboard shortcuts of note, if you're going to go off of the screen-recording:
CTRL+E, CTRL+SHIFT+[Arrow]
- new editor groupCTRL+E, CTRL+[Arrow]
- move focus to groupSorry (🍁) that this issue is so insanely long. I really wanted to make sure that it is accurate and reproducible to maximize the odds of it getting fixed: it's really getting in the way of my attempt to use my mouse less 😄.
Edit: I ran the
F1 > Help: Troubleshoot Issue
command and followed the steps. I've added my results as a comment.The text was updated successfully, but these errors were encountered: