adobe/brackets — pull request #2314 by njx (2012-12-08 09:03:18+00:00)
Title: INITIAL REVIEW: Move Find dialog out of editor

For #2095, this moves the Find bar out of the editor and into the toolbar. The visual appearance is similar to what we have today, and the functional behavior should be the same. The main difference is that the Find bar no longer overlaps the editor content, so if a found item scrolls to the top of the viewport, it's no longer hidden by the Find bar. Find in Files and Quick Open were changed to use the same implementation.

To do this, I replaced the dialog.js implementation we were using from CodeMirror with a new class, ModalBar, that mimics the same functionality but does not create the bar inside the CodeMirror wrapper element. If ModalBar is constructed with `autoClose` set to `true`, it mimics the CodeMirror dialog.js functionality of closing the dialog on Return and Esc keys and blur events, but dispatches its own events for those cases instead of calling a callback. Find/Replace uses this functionality, whereas Find in Files and Quick Open don't.

Additionally, whenever the ModalBar appears or disappears, it attempts to preserve the apparent scroll position in the editor, so the code doesn't shift around. The only case where it can't do this is if the editor is scrolled all the way to the top while the ModalBar is open--in that case, of course, it's not possible to keep the code in the same place; it has to shift back up.

Note that there are a couple of bugs I know about in this implementation (which is why it's just up for initial review):

* When the Quick Open bar closes, the code shifts upward. I'm pretty sure this is because of the hack we're doing when closing the bar (see the comment online #380); removing the raw DOM node makes it so `ModalBar.close()` can't figure out how much to scroll back up (since it needs to measure its current height, and that height will be 0 if the DOM node has already been removed). I can think of some workarounds, but want to consult with @peterflynn about the hack first.
* When an invalid regexp is entered, the parse error message shows up as before, pushing the editor downward and causing the status bar to disappear. I could add code to fix this, but want to think about alternatives for showing the error state.

In a separate branch, I actually have a much more radical replacement for Find/Replace that unifies them into a single modal bar and eliminates a good deal of the messy code (and simplifies ModalBar as well), getting closer to the Find/Replace design that's in the original Northstar. It has one bug I'm having trouble figuring out, but if I can get that figured out, we might want to go ahead and just go straight to that version. I'll consult with some folks before putting up that pull request though.