atom/fuzzy-finder — pull request #52 by izuzak (2014-07-06 19:58:50+00:00)
Title: Jump to line in active editor if query starts with a colon

Fixes #27

Currently, using the `:NN` syntax to jump to a line in the active edtior doesn't always work (using `foo.txt:NN` works, however). The reason why this is so is that fuzzy finder's list of items is not filtered to include only
the active editor and the previously opened editor is pushed to the top of the list ([1](https://github.com/atom/fuzzy-finder/blob/f90e03c8da44b44067cb44bd6e2aeab6c79ee226/lib/buffer-view.coffee#L22-L26), [2](https://github.com/atom/fuzzy-finder/blob/f90e03c8da44b44067cb44bd6e2aeab6c79ee226/lib/project-view.coffee#L82-L96)). As a result, typing just `:12` will keep the top item in the list selected (which is rarely the active file), and will instead open a different file when `core:confirm` is triggered.

This pull request changes the fuzzy finder so that using the `:NN` syntax will always jump to line `NN` in the active view, if the active view is an editor (including unsaved editors).

**Summary of changes**

First, f371525 makes the following changes to the related tests:
* splits the current test for the `:NN` syntax into two parts, since they are unrelated
* adds a new test, so that there are three tests in total for the `:NN` syntax: a test for `foo.txt:NN`, a test for `:NN`, and a test for `:NN` when split panes is used.
* modifies the `:NN` test so that the reported issue causes the test to break. Currently, the test isn't failing because a buffer finder is used with only one buffer opened. As a result, there was always only one item in fuzzy finder's lists, so using `:NN` always worked.

To force the issue to manifest -- another file is opened, so that there are two items in fuzzy finder. With these changes, the test expectedly fails on the current implementation of fuzzy finder.

Then, 9761e32 changes the fuzzy finder to correctly support the `:NN` syntax
* `confirmSelection` and `populateList` methods of `SelectListView` are overriden, and `confirmed` and `splitOpenPath` are modified to detect that the `:NN` syntax is used. If so, then the list of items is cleared (matching the behavior of SublimeText) and a message is shown to the user to explain the behavior. Triggering `core:confirm` in that situation performs the `moveToLine` action on the active editor.
* the `:NN` tests are modified so that they verify that no items are in the list.

Here's how that looks with these changes:

![](https://cloud.githubusercontent.com/assets/38924/3489800/eedd12f4-0546-11e4-99a9-f0e952e98008.gif)

cc @nathansobo @kevinsawicki for :eyes: :microscope:

---

Note: I've tried a few different approaches to tackle this (e.g. showing just a single item in the list when `:NN` is used, i.e. the active editor). However, these other approaches fell short in one way or the other (e.g. the one-item-in-list approach doesn't really work with unsaved editors). If anyone has an idea about a cleaner way to do this -- I'm happy to give it a try! :surfer: