0

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?

Johnny Willemsen
  • 2,942
  • 1
  • 14
  • 16
  • What do you mean by behind one step? Where in the application are you trying to get the value? – Jordan Davis Aug 06 '15 at 03:22
  • I have a template with the Ace editor and a {{markdown}} template. There is a helper for the content. Template.zenoEditor.helpers ({ docid: function () { return Session.get("document"); }, document: function () { return ace.edit("editor").getValue(); } }); When I select a document from the list the markdown shows the last one selected not the current one. Im using the example that comes with the package. – Philip Beadle Aug 06 '15 at 03:30
  • Ive uploaded it here http://zeno.meteor.com/zeno-editor, you can see how the rendered markdown is for the last selected item. – Philip Beadle Aug 06 '15 at 03:39
  • code is here https://github.com/Phils-Ideas/zeno – Philip Beadle Aug 06 '15 at 03:57

1 Answers1

0

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.

Jordan Davis
  • 1,271
  • 14
  • 24
  • Thanx, I did something similar and called Tracker.flush() after the docId is changed. I removed the {{#with docid}} too. – Philip Beadle Aug 11 '15 at 01:01