Get/set text of atom-text-editor


#1

Trying to add simple view to my package.

line_edit = document.createElement("atom-text-editor")
line_edit.setAttribute("mini", "")
root.appendChild(line_edit)

How can I get/set text of this line_edit from code?


#2

Anyone? :disappointed_relieved:


#4

I’m trying to add view to my package. There is no native frameworks for creating «gui» (spaceman abandoned as I realsized), so there are advices to use «just html» (or your favorite js lib for that). I’m creating html elements and use https://atom.io/docs/api/v1.4.3/Workspace#instance-addModalPanel. I can show/hide it, everything is ok, but I don’t understand how to get/set text from my input field/editor, which is atom-text-editor html tag.


#6

Here’s how you can do with your current code:

line_edit = document.createElement("atom-text-editor")
line_edit.setAttribute("mini", "")
root.appendChild(line_edit)

line_edit_model = line_edit.getModel()
line_edit_model.setText('my text')

And here’s how I would rather do:

line_edit_model = atom.workspace.buildTextEditor(mini: true)
line_edit_model.setText('my text')
line_edit = atom.views.getView(line_edit_model)
root.appendChild(line_edit)

#7

@mark_hahn
@abe
Great! Thank you!


#8

I apologize for the incorrect suggestions. I was not aware of this way of creating things. I need to learn how things work now.


#9

No problem :), I think it’s not really made explicit in the docs either so it’s no wonder you may have missed it.
Actually I like that you can just put a <atom-text-editor> some where and get everything working, but you have to know the proper API to use to then access the model.