How to close TextEditor when editor closes or reloads



I am now writing a package that would open a new TextEditor on the right side pane for the selected TextEditor.
For example:

    | A | B | 

I select A editor and then after run package, B editor will be open.

My question is that is there way to close editor B when atom editor closes or reloads? (Any API I can use?)
So next time I restart atom editor, B will not shown.



I would use the pane’s onWillDestroy event to close any of your special instances. This covers not only Atom exiting and windows reloading, but someone simply closing that one window.


Hi @leedohm ,

I just tried onWillDestory and it doesn’t work as I expect.

I think I didn’t state the question clearly.

My problem is like the gif.
I run my package, it then will open a text editor on the right side. After I reload the atom editor, the right side text editor is still there…

I used

// open new pane to show html, {
      split: "right",
      activatePane: false,
      searchAllPanes: true
    .then(function(editor) {

Thank you very much!


Yes, I understood what you’re asking for. You want it to not show up when Atom is launched the next time. This goes against the way that Atom is designed in that the user is in control of what is restored, not package authors. If you really want to go against that, you should probably warn users that your package specifically breaks this assumption.

There is no “Atom is exiting” or “window is closing” event (at least not in the renderer process), the best you can do is one of the various onWillDestroy events. So if you want to work around this, you’ll probably need to dig into the state serialization code to see when it is called and figure out how to get in front of that.