diff --git a/common/src/app/common/types/text.cljc b/common/src/app/common/types/text.cljc index a7b42372bf..3353729023 100644 --- a/common/src/app/common/types/text.cljc +++ b/common/src/app/common/types/text.cljc @@ -690,11 +690,13 @@ no-letters? (not (some #(seq (:text % "")) (:children paragraph))) node (dissoc paragraph :children)] (if no-letters? - (let [run (-> paragraph :children first (dissoc :text))] + (let [run (-> paragraph :children first (dissoc :text)) + ;; its index in `runs`, taken before the run is added to them + ri (count runs)] (recur (inc i) (conj! runs {:paragraph i :node run :empty? true}) letters - (conj! paragraphs' (assoc node :empty-run run :empty-ri (count runs))))) + (conj! paragraphs' (assoc node :empty-run run :empty-ri ri)))) (recur (inc i) runs letters (conj! paragraphs' node)))))))) (defn letters->content diff --git a/common/test/common_tests/types/text_letters_test.cljc b/common/test/common_tests/types/text_letters_test.cljc index cd4c067670..3f56cc4368 100644 --- a/common/test/common_tests/types/text_letters_test.cljc +++ b/common/test/common_tests/types/text_letters_test.cljc @@ -63,7 +63,16 @@ (map #(get-in % [:run :font-weight]) (:letters letters)))) (t/testing "a paragraph with no letters keeps its run" (t/is (= [false true false] (map #(contains? % :empty-run) (:paragraphs letters)))) - (t/is (nil? (some :children (:paragraphs letters))))))) + (t/is (nil? (some :children (:paragraphs letters))))) + (t/testing "and its index among the runs" + (t/is (= 2 (get-in letters [:paragraphs 1 :empty-ri]))) + (t/is (:empty? (get-in letters [:runs 2])))))) + +(t/deftest a-copy-ending-in-an-empty-paragraph-is-compared-with-its-main + ;; the empty paragraph's run is the last of the copy's runs + (let [main (thtx/content [[["Label"]]]) + copy (thtx/content [[["Copy"]] [[""]]])] + (t/is (contains? (cttx/override-groups main copy) :text-content-text)))) (t/deftest letters-build-the-content-back (doseq [text [[[["Hello world"]]]