How to reference a new tab opened via atom.workspace.open


#1

Hi there.

I’m writing a package and I’m using atom.workspace.open to add a new tab (or pane) to show there the content, but the problem I have is that I don’t know how I can add the content because I don’t know how to get the reference to it.

I have seen that exists atom-space-pen-views but is deprecated and I would like to use (if it’s possible) another option.


#2

atom.workspace.open() returns a Promise which resolves into a TextEditor after it has been created successfully. The easiest way to get this is to use promise.then(), like so:

atom.workspace.open(uri, options).then( (newEditor) -> {
  newEditor.setText(text)
})

#3

I think this not what I want. I’m sorry for not explaining all before.

The package I’m doing uses atom-select-list to choose any of the options that will be available and when the user selects one it opens and uri using atom.workspace.open():

didConfirmSelection: data => {
  atom.workspace.open(`my-package-uri://${data.name}`, { data });
  this.cancel();
}

On the activate() method from my main file I add an opener:

return atom.workspace.addOpener((uri, options) => {
  if (!uri.match(/my\-package\-uri/)) {
    return;
  }

  new MyPackageView(options);
});

#4

I don’t feel like I can see enough of the picture to change my original supposition. Where in your package’s workflow does it need to find a specific editor? You don’t have to maintain the reference if you can easily find it again, or you might need to change some things if you really want to maintain the reference.