How to create editor and focus on it


#1

Now to create editor I use
inField = document.createElement(‘atom-text-editor’)
inField.setAttribute(‘mini’, ‘’)
editor = inField.getModel()
Is there better way to do it?

And I want to create function which will make editor focused
atom.workspace.paneForItem(editor).activate()
doesn’t work because editor doesn’t have own pane


#2

Hello.

I am guessing what you are looking for is:
(click to view)
atom.workspace.open()

Executing the command without parameters will open an empty editor and settle focus on it. Else the parameters can tell it what to open, in which pane, and where to focus the cursor.

Is that what you are looking for? Perhaps something else…?
Cheers.


#3

That’s not what I need. I have a pane with several elements, one of which is mini editor. I want it to become focused when user activates this pane. I know, how to make it

  atom.workspace.onDidChangeActivePaneItem( (item) ->
    if item is myItem
      # I need to write here something to focus on editor

My pane looks like

<div>
  <div> ... </div>
  <div>
    editor.mini
    ...
  </div>
</div>

#4

From my understanding the open command should be able to focus on an already created item.
…not sure if it applies to ‘mini’ or if the command actually does as advertised.

Okay… Perhaps the following project will be of more interest:
Focus fix 3 (#276)
Focus on the mentioned issue and see if there are some ideas that are helpful.


#5

Thank you, it was very useful.

Actually, I found how to focus on editor

  @editor.element?.focus()

#6

Thanks for the feedback.
…more so for sharing the solution.


TAGS: coding for atom in atom, focus loss, focus, pane, workspace, open editor, mini, coffeescript