Filter text editor lines by hiding some


Hey all!

Trying to think through how I might implement a filtering feature for Based on an issue posted about having a query language style system. I would want the user to be able to type in a filter into a custom input and have it “hide” lines that don’t match, while still keeping the core data for them intact. Sort of like how folding works where it keeps line numbers correctly listed, so saving the file won’t delete the filtered out items, but it can help to focus the tasks that are visible.

Does anyone have any suggestions on how to approach this? Any packages that already do something similar? At least I can use the built-in search capabilities, but it seems like it would be nice to have some more complex querying available.



Instead of trying to write something that assumes that the list of tasks is a text file and trying to tweak a text editor into doing what you want, you can also use the text format as a serialization format. You read the tasks from disk and convert them to some data structure. Then you create an HTML UI for that task list and provide your own commands for the tasks. The commands modify the data structure and update the view. Then you allow the user to save, which takes the data structure and serializes it to disk.

That’s how they did it for the various git modules: Instead of piping the output of the git commands into some text editor and parsing the text via some grammar, and adding commands that do stuff with the text based on the cursor position – they wrote a new HTML based UI for it.

I think Atom still needs to grow because if you create your own HTML UI, chances are it will look and feel different from other (putatively similar) HTML UIs in other packages, and it might not match the look and feel of the normal text editors. (For example, the text entry field for writing the task description should be a text editor with normal Atom commands so that Ctrl-M goes to the matching parenthesis and all that jazz.) But it looks to me that this is the direction it’s going.


I definitely see what you are saying. It would make sense to write an entirely custom UI to replace the default atom text editor, which would give way more control over the output. That’s one of the greatest features of Atom in that it’s entirely customizable. I’ve certainly come across issues working with the grammar structure that would be alleviated by a custom UI. Any suggestions on where to look for hooking into the file serialization process, or would I do this manually with Node’s FS module? I could write a custom view module, but is there a way to force that to open instead of the default text editor when a certain file is accessed?

I’m still interested to know if anyone has any thoughts on the alternative. A full custom UI is going to be a pretty big undertaking!


Yes. See html-tab as an example of creating your own tab contents.

Here is an example on how to watch for a file open and redirect it to your own page. This one looks for files > 2 mb.

    @opener = (filePath, options) =>
      if fs.getSizeSync(filePath) >= 2 * 1048576 
        new Viewer filePath
    atom.workspace.registerOpener @opener


That’s a really great feature. Thanks @mark_hahn! I may have to start planning the next version of the plugin so it’ll be a completely custom interface. The only worry I have is that I really like using Vim Mode, so I imagine there will be some awkwardness in being able to select multiple items, but that might not be so bad. I could probably pull across a couple of the helpers manually.


sorry for reviving this old topic!
Is there any way this can be done to a normal search in file, you know keep all lines that are not matched by the search hidden while I edit only the relevant ones?