adobe/brackets — pull request #2560 by njx (2013-01-16 03:07:34+00:00)
Title: If you hit Cmd-F while search bar is already open, just select existing query

@peterflynn

For #2478, I think the expected behavior from the user's point of view should be that focus stays in the Find bar and the current query text is selected.

The main bug was that when creating a new modal bar, the old one would autoclose itself (because it would lose focus), but there was a timing issue where a focus change would get sent out and the new modal bar would also autoclose itself. The old CodeMirror "dialog" handled this by adding a timeout within which it would ignore focus changes, but that seemed like a big hack and I didn't want to reinstate it. So, we simply always close the modal bar explicitly before creating a new one; and if you start a new search while the old one is open, we just copy over the query from the old one instead of using the selected text (which might differ in capitalization from the old query).

I tried a more straightforward fix--instead of closing and reopening the modal bar in this case, just set focus to the existing one. But skipping over the "new modal bar" logic in `doSearch()` led to other weird behavior, like the search cursor position not getting reset to the current cursor position. Rather than try to refactor all that logic and possibly break other cases, I decided to try to use the existing logic as much as possible.

In the future, we need to really clean up how all this stuff works and get rid of the last vestiges of the old CodeMirror approach. (I had started this in my "unified find/replace" branch--in that branch, we more explicitly control the opening and closing of the modal bar.)