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

Tool window doesn't get focused when opened #42

Open
alirezamirian opened this issue May 18, 2023 · 0 comments
Open

Tool window doesn't get focused when opened #42

alirezamirian opened this issue May 18, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@alirezamirian
Copy link
Owner

alirezamirian commented May 18, 2023

Reproduction scenario:

  1. Within the left side, have two tool windows; one at the top (primary) and one at the bottom (secondary).
  2. Open the secondary, leaving the primary closed.
  3. Open the primary.
    The focus should be moved to the primary tool window when it opens, but it will remain in the secondary.

Problem

The focus doesn't actually "remain" within the secondary tool window. The secondary tool window is remounted as the primary window is mounted. Both will attempt to autofocus on mount and the second one wins, simply because it's rendered after the primary one.

Explanation

In SideDockedState, primary and secondary tool windows are normalized into a main and split view. When only the secondary window is opened, it will take up the main slot. When both windows are open, the secondary window will take up the split slot. So the secondary window will be re-mounted because it's moved across react tree.

Potential solution

Always render the primary and secondary windows in the same place in react tree. Render null if one is empty. There may be a need for change in ThreeViewSplitter, in case it doesn't properly support only passing lastView.

Test case

it("opens and focuses tool window (in the same anchor) if currently closed", () => {
cy.mount(
<ThemeProvider theme={new Theme(darculaThemeJson as any)}>
<WithActivateToolWindowKeymap
initialState={{
"First window": toolWindowState({ anchor: "left" }),
"Second window": toolWindowState({
anchor: "left",
isSplit: true,
isVisible: true,
}),
}}
/>
</ThemeProvider>
);
cy.realPress(["Meta", "1"]);
cy.findByTestId("First window").should("exist");
/**
* Known issue: https://github.com/alirezamirian/jui/issues/42
* Inverted assertion, in the absence of it.fail(). Just to make sure it will not be overlooked when the issue
* is resolved. The assertion should be `.should("have.focus")`.
*/
cy.findByTestId("First window")
.find("input")
.eq(0)
.should("not.have.focus");
});

alirezamirian added a commit that referenced this issue May 18, 2023
alirezamirian added a commit that referenced this issue May 18, 2023
@alirezamirian alirezamirian added the bug Something isn't working label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant