Skip to content

Commit

Permalink
BUG / fixed some text editor bug with duplicated text content
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-ev committed Feb 20, 2023
1 parent 23b2e78 commit 0d754be
Showing 1 changed file with 25 additions and 13 deletions.
Expand Up @@ -145,6 +145,8 @@ export default {
debounce_textUpdate: undefined,
is_collaborative: true,
collaborative_is_loaded: false,
autosave: true,
editor_is_enabled: false,
doc: undefined,
Expand Down Expand Up @@ -455,25 +457,17 @@ export default {
}
this.editor.history.clear();
this.editor.on("text-change", (delta, oldDelta, source) => {
console.log(`CollaborativeEditor / text-change w source ${source}`);
if (source === "user") {
this.doc.submitOp(delta, { source: this.editor_id });
console.log(
`CollaborativeEditor / submitted op to server ${JSON.stringify(
delta
)}`
);
this.updateTextMedia();
}
});
this.editor.on("text-change", this.submitOPAndSave);
this.doc.on("op", (op, source) => {
console.log(`CollaborativeEditor / op applied`);
this.text_deltas = this.doc.data;
if (source === this.editor_id) return;
console.log(`CollaborativeEditor / outside op applied`);
this.editor.updateContents(op);
});
this.collaborative_is_loaded = true;
});
this.doc.on("error", (err) => {
Expand All @@ -484,7 +478,25 @@ export default {
},
endCollaborative() {
if (this.rtc.socket) this.rtc.socket.close();
if (this.doc) this.doc.unsubscribe();
if (this.doc) {
this.doc.unsubscribe();
this.doc = null;
}
this.editor.off("text-change", this.submitOPAndSave);
this.collaborative_is_loaded = false;
},
submitOPAndSave(delta, oldDelta, source) {
console.log(`CollaborativeEditor / text-change w source ${source}`);
if (source === "user") {
this.doc.submitOp(delta, { source: this.editor_id });
console.log(
`CollaborativeEditor / submitted op to server ${JSON.stringify(
delta
)}`
);
this.updateTextMedia();
}
},
updateTextMedia() {
Expand Down

0 comments on commit 0d754be

Please sign in to comment.