mizzao / meteor-sharejs

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

ShareJS.model.on('applyOp',... causes textarea to lose focus #88

Closed derdaumen closed 6 years ago

derdaumen commented 7 years ago

@DavidSichau After implementing your example from issue Failed to get ops #81

ShareJS.model.on('applyOp', Meteor.bindEnvironment((docId, opData, snapshot) => {
        // do not log original document
        if (opData.v > 0) {
            updateCollection(docId, snapshot);
        }
    }, (error) => {
        console.log('Failed to bind environment applyOp', error);
    }));

my textarea now loses focus after each operation.

The problem occurred after implementing this listener. I wonder if you aren't experiencing this behaviour. I'm clueless as to what else might be the cause if not the listener as copied from your example.

I'd appreciate any hints or ideas.

DavidSichau commented 7 years ago

Hi I think this should not be related, as this is Server side code, and should not have an effect on the client side.

The only way it could have an influcence is if you have a publication on your collection and insert text from the collection on the client side. This should be avoided and therefore I add the text also on the server side:

 ShareJS.model.on('create', Meteor.bindEnvironment((docName) => {
        const md = MDs.findOne(docName);
        const opData = {
            op: [{ i: md.md, p: 0 }],
            v: 0,
            meta: {},
        };
        ShareJS.model.applyOp(docName, opData, (err) => {
            if (err) {
                console.log(err);
            }
        });
    }, () => {
        console.log('Failed to bind environment create');
    }));