New file added in atom editor


#1

I want detect that user has created a new file in atom editor and on the basis I want to call a method. I had figured out that can be done using

atom.workspace.onDidAddTextEditor(( textEditor, pane, index) => {
      // Path of file  added
    });

In the above function I want to get the path of the file added … how can I do that??? can anyone suggest…


#2

Protip: use ``` at the beginning and end of your code to have it show up as actual code and preserve indentation.

Be aware that atom.workspace.getCenter().onDidAddTextEditor fires when a new text editor is added, which may or may not be a new file. However, if that’s ok for your use case, here’s how I would do it:

atom.workspace.getCenter().onDidAddTextEditor({textEditor, pane, index}) => {
  console.log(textEditor.getPath()); // => path of text editor
});

#3
  atom.workspace.getCenter().onDidAddTextEditor(({textEditor, pane, index}) => {
      console.log(textEditor.getPath()); // => path of text editor
    });

I had used it… but it is printing undefined in console.