-
Notifications
You must be signed in to change notification settings - Fork 93
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
Focus the viewpane on the next tick #2903
Conversation
Of course the problem happens with other panes like Variables. So I've gone ahead and implemented the This class sets I'm not sure why we need to focus at the next tick when VS Code panes don't. It feels like I'm missing something, but at least this is now working properly. |
10e29b1
to
2652e9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me. I would imagine the reason we need a timeout but vscode doesn't is that react may not render perfectly on the next tick. E.g. there may be a set state or something that causes a redraw of the dom that the react dom-diff algorithm doesn't know how to handle with focus. Also, it looks like a whole bunch of overrides are done for ViewPane.focus()
, so it doesn't seem like a real code-smell.
this.focusElement(); | ||
} | ||
}; | ||
disposableTimeout(focus, 0, this._disposableStore); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course this exists in async.ts
! Good find!
Co-authored-by: Nick Strayer <[email protected]> Signed-off-by: Lionel Henry <[email protected]>
Follow-up to #2867
Addresses another aspect of #811
Closes #2904
Intent
Prevent panel toggling from breaking viewpane toggling when there is no focusable element in the pane.
Approach
In #2867 we made viewpanes focusable by giving them a
tabIndex
. TheViewPane::focus()
method (called viasuper.focus()
) is in charge of focusing that pane. This allowsfocus()
to succeed, which is necessary for viewpane toggling to work as expected.However when you toggle the whole panel (e.g. with Cmd-J or the icon in the top-right), as opposed to toggling specifically the console viewpane, our
focus()
method is called too early before the pane is mounted to the DOM. This causes the focus call to fails, which then breaks viewpane toggling. To work around that I put our input focus call in a timeout. But because I didn't do the same withsuper.focus()
, we can still get in a broken state by toggling the whole pane when there is no input to focus, which can happen during runtime discovery or when a runtime has crashed during startup. This PR fixes that omission.I also added the comment that you requested in the other PR @nstrayer.
QA Notes
One way of reproducing is to disable automatic startup of interpreters. Without starting an interpreter, use the viewpane toggling command:
Do this a few times and you should see the console toggle.
Now use the panel toggling command, e.g. Cmd-J by default on mac (or the secondary side bar if the console is there). Do this a few times, it should work. However, before the fix, the console toggling command would now be broken. With the fix you should still be able to use it.