mizzao / meteor-sharejs

Meteor smart package for transparently adding ShareJS editors to an app
MIT License
225 stars 53 forks source link

Editor content disappears #60

Closed caalberts closed 8 years ago

caalberts commented 8 years ago

I've set up meteor + sharejs + cm, and I have a mongodb collection called Files which I use as the base for the editor content. However, every time I load render a new file into the editor, the file content will be loaded and immediately it disappears and the editor goes blank.

If I look into the mongodb docs collection for the respective fileId, it shows a blank snapshot instead of the content I loaded from the file.

{{> sharejsCM docid=fileId onRender=config id="editor"}}
Template.editor.helpers({
  fileId: function () {
    return Session.get('fileId')
  },
  config: function () {
    console.log('config helper')
    return function (cm) {
      const file = Files.findOne({ _id: Session.get('fileId') })

      cm.setOption('lineNumbers', true)

      // set content of the editor to the latest content from file object
      console.log(Session.get('fileId'))
      console.log(cm)
      // cm.doc.setValue(file.content)
      cm.doc.setValue('hello world')

      // periodically update file object when there is a change in the editor
      cm.doc.on('change', _.debounce(function (editor) {
        // Files.update({ _id: file._id }, { $set : { content: editor.getValue() } })
      }, 500))
    }
  }
})
DavidSichau commented 8 years ago

Could you provide me with an small example app, where I can try out if I figure out what causes this problem?

DavidSichau commented 8 years ago

Closed as no response.