I’m currently working on a mechanism to print stuff in a TextEditor. I would like Atom to reuse the same Editor if still open, otherwise a new Editor should be created. So, my code looks pretty much like this:
printStuff: (stuff) -> @printMessageOn 'console-output', stuff printMessageOn: (editorName, message) -> editor = @getEditorByName editorName editor.insertText message getEditorByName: (name) -> editor = atom.workspace.getTextEditors().find (e) -> e.getTitle() is name return editor
getEditorByName method I would like to create a new TextEditor with the required name when it does not exist. Problem is,
atom.workspace.open returns a Promise, and I would like to avoid handling promises outside the method. I found the
buildTextEditor method, but when I use it the new TextEditor is not displayed.
Any suggestions on how to solve this? Cheerio!