浏览代码

fix: Disappearing children

close #4814
Tienson Qin 3 年之前
父节点
当前提交
2b0a56018c
共有 4 个文件被更改,包括 27 次插入1 次删除
  1. 2 0
      .gitignore
  2. 21 0
      e2e-tests/editor.spec.ts
  3. 1 0
      e2e-tests/utils.ts
  4. 3 1
      src/main/frontend/db/model.cljs

+ 2 - 0
.gitignore

@@ -40,3 +40,5 @@ charlie/
 docker
 android/app/src/main/assets/capacitor.plugin.json
 ios/App/App/capacitor.config.json
+
+startup.png

+ 21 - 0
e2e-tests/editor.spec.ts

@@ -65,6 +65,27 @@ test('hashtag and quare brackets in same line #4178', async ({ page }) => {
   )
 })
 
+test('disappeared children #4814', async ({ page }) => {
+  await createRandomPage(page)
+
+  await page.type('textarea >> nth=0', 'parent')
+  await enterNextBlock(page)
+  await page.press('textarea >> nth=0', 'Tab')
+
+  for (let i = 0; i < 6; i++) {
+    await page.type('textarea >> nth=0', i.toString())
+    await enterNextBlock(page)
+  }
+
+  // collapse
+  await page.press('textarea >> nth=0', 'Control+ArrowUp')
+
+  // expand
+  await page.press('textarea >> nth=0', 'Control+ArrowDown')
+
+  await page.waitForSelector('.ls-block >> nth=6') // 7 blocks
+})
+
 // FIXME: ClipboardItem is not defined when running with this test
 // test('copy & paste block ref and replace its content', async ({ page }) => {
 //   await createRandomPage(page)

+ 1 - 0
e2e-tests/utils.ts

@@ -81,6 +81,7 @@ export async function lastBlock(page: Page): Promise<Locator> {
 export async function enterNextBlock(page: Page): Promise<Locator> {
   let blockCount = await page.locator('.page-blocks-inner .ls-block').count()
   await page.press('textarea >> nth=0', 'Enter')
+  await page.waitForTimeout(10)
   await page.waitForSelector(`.ls-block >> nth=${blockCount} >> textarea`, { state: 'visible' })
   return page.locator('textarea >> nth=0')
 }

+ 3 - 1
src/main/frontend/db/model.cljs

@@ -671,7 +671,9 @@
                                                                                (remove nil?))]
                                                                [(zipmap (mapv :db/id blocks) blocks)
                                                                 (zipmap (mapv :db/id @result) @result)]))
-                           limit (if (and result @result) (+ (count @result) 5) limit)
+                           limit (if (and result @result)
+                                   (max (+ (count @result) 5) limit)
+                                   limit)
                            outliner-op (get-in tx-report [:tx-meta :outliner-op])
                            blocks (build-paginated-blocks-from-cache repo-url tx-report result outliner-op page-id block-id tx-block-ids scoped-block-id)
                            blocks (or blocks