Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Ace Editor object from its Div id

I have a div which instantiates an ace editor object.

I am trying to drag and drop some text into it from an HTML draggable.

I have made the ui-ace div droppable and want to get the current instance of the editor from the event target of drop.

How can I accomplish this???

HTML

<div id="id1" ui-ace droppable=true ondrop="handleDrop(event,this)"></div>

JS function

function handleDrop(e,obj){
   // need code to get current editor instance from obj without using ace.edit(obj.id)
   // because ace.edit(obj.id) will reset the content I believe. Please correct me if I am 
   //wrong. Ace api says it will insert editor in the DOM. http://ace.c9.io/#nav=api&api=ace
}

Please help.

like image 911
user3779089 Avatar asked Aug 22 '14 17:08

user3779089


People also ask

How do I get an ace editor value?

Getting/Setting Values: var code = editor. getValue(); editor. setValue("new code here");


1 Answers

I don't know why this is not mentioned in the API documentation, but if you call ace.edit on an already instantiated editor, you will get that instance. It will NOT reset that editor. I have tested it.

In your case, it could be accomplished by the following code:

function handleDrop(e,obj)
{
   var editor = ace.edit(obj.id);

   // Do something with editor
}

I know it has been a while since you have asked this question, but I couldn't find anything on this topic so I thought I should share this.

like image 199
Yoav Kadosh Avatar answered Oct 07 '22 00:10

Yoav Kadosh