The Wayback Machine - https://web.archive.org/web/20240823150621/https://github.com/atom/find-and-replace/pull/645
Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Focus project-find search input upon toggle #645

Merged
merged 5 commits into from
Feb 1, 2016
Merged

Focus project-find search input upon toggle #645

merged 5 commits into from
Feb 1, 2016

Conversation

felixjung
Copy link
Contributor

This PR adds the following change: when toggling the project-find panel via the project-find:toggle command from an invisible state, the search input is focused after the panel becomes visible. This is preferable for the following reasons:

  • This exact behaviour is the default for the find-and-replace:toggle command. Enabling the same behaviour for project-find:toggle makes find-and-replace more consistent from a UX perspective.
  • Some people prefer to use toggling instead of showing and dismissing via Esc and create according key bindings in their keymap.cson. In such cases it's convenient to also focus the search input.
@@ -72,6 +72,7 @@ module.exports =
@projectFindPanel.hide()
else
@projectFindPanel.show()
@projectFindView.focusFindElement()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than just adding the one missing line, maybe we could turn these two implementations into a common function so that find and find-in-project always work the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that would make sense. I guess in that case we can do the same for other functions like show. Most of these functions seem to share some actions:

  • Create the view.
  • Disable 'the other find panel'.
  • Show/hide the correct find panel.
  • Optionally focus a specific element.

I would propose the following changes:

  1. Write a function that determines 'the other find panel' based on the panel to be activated.
  2. Generalize functions so that they take a panel to activate and an optional action like 'focus input x' as arguments.

What do you think? I'll try to write some more code soonish.

@felixjung
Copy link
Contributor Author

I've generalized the toggle and show functions for the two panels. I think I stumbled upon a scoping bug for the project-find view. Functions were defined with -> rather than => and thus the focusing did not work (see d550e62 for details).

@findPanel.hide()
@projectFindPanel.show()
@projectFindView.focusFindElement()
showPanel @projectFindPanel, @findPanel, @projectFindView.focusFindElement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👕 Some extra whitespace at the end of this line

@felixjung
Copy link
Contributor Author

How sloppy...

@felixjung
Copy link
Contributor Author

Do these functions need unit tests?

@lee-dohm
Copy link
Contributor

It's preferable if you can add unit tests for these, yes. That way we can be relatively certain we don't accidentally break them as things move forward.

@felixjung
Copy link
Contributor Author

I will try to figure out how to write these UI tests based on the existing tests for the package. Thanks @lee-dohm.

benogle added a commit that referenced this pull request Feb 1, 2016
Focus project-find search input upon toggle
@benogle benogle merged commit 3caa01b into atom:master Feb 1, 2016
@benogle
Copy link
Contributor

benogle commented Feb 1, 2016

Thanks!

@felixjung
Copy link
Contributor Author

But the tests were still missing o_O

@lee-dohm
Copy link
Contributor

lee-dohm commented Feb 2, 2016

It would be great if you could submit a separate PR for the tests 😀

@felixjung
Copy link
Contributor Author

Ahahahah, will try. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants