How can I get the path of the focused TextEditor (the one with the blinking cursor)?


#1

I have been looking around the documentation for a way to get the file path of the focused TextEditor’s file.
I can get all the path of all the TextEditors with

for editorView in atom.workspaceView.getEditorViews()
   console.log(editorView.getModel().getPath())

But I can’t find a property or class that could tell me if the referenced EditorView is the one that is focused on (with the TextEditorView with a blinking cursor)

Please advise.


#2
atom.workspace.getActivePaneItem()

#3

Atom is shifting towards using the Models for things rather than the views. So rather than using atom.workspaceView, you’ll find it easier if you go through the Workspace Model, i.e. atom.workspace:

editor = atom.workspace.getActiveTextEditor()

See: https://atom.io/docs/api/latest/Workspace#instance-getActiveTextEditor


#4

Thanks! That’s what I needed.


#5

I answered his question incorrectly but my solution is a valid required one if the item is not a TextEditor. Two or three of my packages work with tab items that can be any item.