diff --git a/crates/loro-internal/src/fork.rs b/crates/loro-internal/src/fork.rs index 0785be4c..2267d2b7 100644 --- a/crates/loro-internal/src/fork.rs +++ b/crates/loro-internal/src/fork.rs @@ -41,6 +41,10 @@ impl LoroDoc { }) .unwrap(); let doc = LoroDoc::new(); + doc.set_config(&self.config); + if self.auto_commit.load(std::sync::atomic::Ordering::Relaxed) { + doc.start_auto_commit(); + } doc.import(&bytes).unwrap(); doc } diff --git a/loro-js/tests/misc.test.ts b/loro-js/tests/misc.test.ts index c4b0f398..72c59f70 100644 --- a/loro-js/tests/misc.test.ts +++ b/loro-js/tests/misc.test.ts @@ -290,6 +290,26 @@ describe("to json", () => { }); }); +it("fork at", () => { + const doc = new LoroDoc(); + doc.setPeerId("0"); + doc.getText("text").insert(0, "Hello, world!"); + console.log("0"); + const newDoc = doc.forkAt([{ peer: "0", counter: 6 }]); + newDoc.setPeerId("1"); + newDoc.getText("text").insert(6, " Alice!"); + // ┌───────────────┐ ┌───────────────┐ + // │ Hello, │◀─┬──│ world! │ + // └───────────────┘ │ └───────────────┘ + // │ + // │ ┌───────────────┐ + // └──│ Alice! │ + // └───────────────┘ + doc.import(newDoc.export({ mode: "update" })); + console.log(doc.getText("text").toString()); // "Hello, world! Alice!" +}); + function one_ms(): Promise { return new Promise((resolve) => setTimeout(resolve, 1)); } +