浏览代码

fix: buggy diff-merge case happens when prepend new blocks before first base block

Junyi Du 2 年之前
父节点
当前提交
6d89f309db
共有 3 个文件被更改,包括 25 次插入24 次删除
  1. 1 1
      package.json
  2. 20 19
      src/test/frontend/fs/diff_merge_test.cljs
  3. 4 4
      yarn.lock

+ 1 - 1
package.json

@@ -91,7 +91,7 @@
         "@excalidraw/excalidraw": "0.12.0",
         "@hugotomazi/capacitor-navigation-bar": "^2.0.0",
         "@logseq/capacitor-file-sync": "0.0.22",
-        "@logseq/diff-merge": "^0.0.1",
+        "@logseq/diff-merge": "^0.0.2",
         "@logseq/react-tweet-embed": "1.3.1-1",
         "@sentry/react": "^6.18.2",
         "@sentry/tracing": "^6.18.2",

+ 20 - 19
src/test/frontend/fs/diff_merge_test.cljs

@@ -1,6 +1,5 @@
 (ns frontend.fs.diff-merge-test
-  (:require [datascript.core :as d]
-            [cljs.test :refer [deftest are is]]
+  (:require [cljs.test :refer [deftest are is]]
             [logseq.db :as ldb]
             [logseq.graph-parser :as graph-parser]
             [frontend.fs.diff-merge :as fs-diff]
@@ -311,29 +310,31 @@
         foo-content (str "- abc\n"
                          "- def\n")
         bar-content (str "- ghi\n"
-                         "\t- jkl\n")]
+                         "\t- jkl\n")
+        foo-new-content (str foo-content "- newline\n")
+        new-bar-content (str  "- newline\n" bar-content)]
     (graph-parser/parse-file conn "foo.md" foo-content {})
     (graph-parser/parse-file conn "bar.md" bar-content {})
-    (are [ast content page-name uuids]
+    ;; Compare if the uuids are the same as those inside DB when the modified content (adding new line) is parsed
+    (are [ast content page-name DB-uuids->new-uuids-fn]
          (= (with-redefs [conn/get-db (constantly @conn)]
               (#'file-common-handler/diff-merge-uuids :markdown ast content {:page-name page-name
                                                                              :block-pattern "-"}))
             ;; Get all uuids under the page
-            (conj (->> page-name
-                       (test-db->diff-blocks conn)
-                       (map :uuid)
-                       (vec)) nil))
+            (->> page-name
+                 (test-db->diff-blocks conn)
+                 (map :uuid)
+                 (vec)
+                 (DB-uuids->new-uuids-fn)))
 
-      (gp-mldoc/->edn (str foo-content "- newline\n") (gp-mldoc/default-config :markdown))
-      (str foo-content "- newline\n")
+      ;; Append a new line to foo
+      (gp-mldoc/->edn foo-new-content (gp-mldoc/default-config :markdown))
+      foo-new-content
       "foo"
-      ["11451400-0000-0000-0000-000000000000"
-       "63246324-6324-6324-6324-632463246324"
-       nil]
-
-      (gp-mldoc/->edn (str bar-content "- newline\n") (gp-mldoc/default-config :markdown))
-      (str bar-content "- newline\n")
+      (fn [db-uuids] (conj db-uuids nil))
+      
+      ;; Prepend a new line to bar
+      (gp-mldoc/->edn new-bar-content (gp-mldoc/default-config :markdown))
+      new-bar-content
       "bar"
-      ["11451411-1111-1111-1111-111111111111"
-       "63241234-1234-1234-1234-123412341234"
-       nil])))
+      (fn [db-uuids] (cons nil db-uuids)))))

+ 4 - 4
yarn.lock

@@ -492,10 +492,10 @@
   resolved "https://registry.yarnpkg.com/@logseq/capacitor-file-sync/-/capacitor-file-sync-0.0.22.tgz#3fa94d40e5c44c70a12537ce17cf3089ff72f93b"
   integrity sha512-lb0+43YAaWy0umBCP2mPKyAPlIr2YHrLBfqGkCJUGAbrhTCAj37KZzb3snwSqeLA8dUSks9PcAN3jSgS74VMMw==
 
-"@logseq/diff-merge@^0.0.1":
-  version "0.0.1"
-  resolved "https://registry.yarnpkg.com/@logseq/diff-merge/-/diff-merge-0.0.1.tgz#75d826a7e6fae96cd624faeea1310438de179ac7"
-  integrity sha512-g69EQOdWDD+zxxCVSTIzWmxCLAoPFZLNxiqPu1TMVsDNol4iJONcToNp2yPI9hgbrXXZ8ajivZJvlY5H7qrKZw==
+"@logseq/diff-merge@^0.0.2":
+  version "0.0.2"
+  resolved "https://registry.yarnpkg.com/@logseq/diff-merge/-/diff-merge-0.0.2.tgz#0bf29a550921311f63754db65ea83b82c54b16c8"
+  integrity sha512-c6V7rTg/pEoqhByJxRv7yyZ7q3LylKmkiKxoU99R7Fr7Cf5j9dn7GUQW/RlOs68IqYv76BkTHR6EhrLf6cKtZg==
 
 "@logseq/[email protected]":
   version "1.3.1-1"