How to get the current text in meteor-sharejs ace editor

210 views Asked by At

Im trying to make a little markdown editor with a panel that shows the rendered markdown. My problem is dont seem to be able to get the current content, it always one step behind. Ive used

return ace.edit("editor").getValue();

Is there a way to bind to the object that the editor is using?

1

There are 1 answers

1
Jordan Davis On BEST ANSWER

Looking at your code, it seems pretty clear that the getValue() is running before the DOM has a chance to update reactively, so it's always grabbing the value that was previously selected. You need to wrap that line in a Tracker.afterFlush:

document: function () {
  Tracker.afterFlush(function(){
    return ace.edit("editor").getValue();
 });
}

Hopefully that will get things working! As an aside, I'm not sure why you are wrapping the {{document}} in {{#with docId}}, seems like it might be expecting a document property in the Documents object. Not sure if this is actually affecting anything, but seeing as you are directly pulling the document from the editor, it's a little confusing.