fix(editor): should delete collapsed siblings when delete heading (#9376)

This commit is contained in:
Flrande
2024-12-30 08:12:03 +00:00
parent 406460a3af
commit 4fee0e2eb3
6 changed files with 70 additions and 112 deletions

View File

@@ -481,12 +481,7 @@ test('should attachment can be deleted', async ({ page }) => {
prop:hidden={false}
prop:index="a0"
prop:lockedBySelf={false}
>
<affine:paragraph
prop:collapsed={false}
prop:type="text"
/>
</affine:note>`,
/>`,
noteId
);
});

View File

@@ -249,7 +249,7 @@ test('should sync selected-blocks to session-manager when clicking drag handle',
await handle.click();
await page.keyboard.press('Backspace');
await assertRichTexts(page, ['', '456', '789']);
await assertRichTexts(page, ['456', '789']);
});
test.fixme(

View File

@@ -59,15 +59,15 @@ test('block level range delete', async ({ page }) => {
await dragBetweenCoords(page, below789, above123);
await pressBackspace(page);
await assertBlockCount(page, 'paragraph', 1);
await assertRichTexts(page, ['']);
await assertBlockCount(page, 'paragraph', 0);
await assertRichTexts(page, []);
await waitNextFrame(page);
await undoByClick(page);
await assertRichTexts(page, ['123', '456', '789']);
await redoByClick(page);
await assertRichTexts(page, ['']);
await assertRichTexts(page, []);
});
test('block level range delete by forwardDelete', async ({ page }) => {
@@ -86,15 +86,15 @@ test('block level range delete by forwardDelete', async ({ page }) => {
await dragBetweenCoords(page, below789, above123);
await pressForwardDelete(page);
await waitNextFrame(page);
await assertBlockCount(page, 'paragraph', 1);
await assertRichTexts(page, ['']);
await assertBlockCount(page, 'paragraph', 0);
await assertRichTexts(page, []);
await waitNextFrame(page);
await undoByClick(page);
await assertRichTexts(page, ['123', '456', '789']);
await redoByClick(page);
await assertRichTexts(page, ['']);
await assertRichTexts(page, []);
});
// XXX: Doesn't simulate full user operation due to backspace cursor issue in Playwright.
@@ -108,9 +108,8 @@ test('select all and delete', async ({ page }) => {
await selectAllByKeyboard(page);
await shamefullyBlurActiveElement(page);
await pressBackspace(page);
await focusRichText(page, 0);
await type(page, 'abc');
await assertRichTexts(page, ['abc']);
await assertBlockCount(page, 'paragraph', 0);
await assertRichTexts(page, []);
});
test('select all and delete by forwardDelete', async ({ page }) => {
@@ -123,9 +122,8 @@ test('select all and delete by forwardDelete', async ({ page }) => {
await selectAllByKeyboard(page);
await shamefullyBlurActiveElement(page);
await pressForwardDelete(page);
await focusRichText(page, 0);
await type(page, 'abc');
await assertRichTexts(page, ['abc']);
await assertBlockCount(page, 'paragraph', 0);
await assertRichTexts(page, []);
});
test('select all should work for multiple notes in doc mode', async ({
@@ -148,7 +146,13 @@ test('select all should work for multiple notes in doc mode', async ({
async function clickListIcon(page: Page, i = 0) {
const locator = page.locator('.affine-list-block__prefix').nth(i);
await locator.click({ force: true });
await locator.click({
force: true,
position: {
x: 2,
y: 2,
},
});
}
test('click the list icon can select and copy', async ({ page }) => {
@@ -179,14 +183,10 @@ test('click the list icon can select and delete', async ({ page }) => {
await initThreeLists(page);
await assertRichTexts(page, ['123', '456', '789']);
await clickListIcon(page, 0);
await clickListIcon(page, 1);
await waitNextFrame(page);
await pressBackspace(page);
await assertRichTexts(page, ['', '456', '789']);
await clickListIcon(page, 0);
await waitNextFrame(page);
await pressBackspace(page);
await assertRichTexts(page, ['', '']);
await assertRichTexts(page, ['123']);
});
test('click the list icon can select and delete by forwardDelete', async ({
@@ -197,14 +197,10 @@ test('click the list icon can select and delete by forwardDelete', async ({
await initThreeLists(page);
await assertRichTexts(page, ['123', '456', '789']);
await clickListIcon(page, 0);
await clickListIcon(page, 1);
await waitNextFrame(page);
await pressForwardDelete(page);
await assertRichTexts(page, ['', '456', '789']);
await clickListIcon(page, 0);
await waitNextFrame(page);
await pressForwardDelete(page);
await assertRichTexts(page, ['', '']);
await assertRichTexts(page, ['123']);
});
test('selection on heavy page', async ({ page }) => {

View File

@@ -154,7 +154,7 @@ test('native range delete by forwardDelete', async ({ page }) => {
await assertRichTexts(page, ['123', '456', '789']);
const box123 = await getRichTextBoundingBox(page, '2');
const inside123 = { x: box123.left - 1, y: box123.top + 1 };
const inside123 = { x: box123.left + 1, y: box123.top + 1 };
const box789 = await getRichTextBoundingBox(page, '4');
const inside789 = { x: box789.right - 1, y: box789.bottom - 1 };
@@ -180,7 +180,7 @@ test('native range input', async ({ page }) => {
await assertRichTexts(page, ['123', '456', '789']);
const box123 = await getRichTextBoundingBox(page, '2');
const inside123 = { x: box123.left - 1, y: box123.top + 1 };
const inside123 = { x: box123.left + 1, y: box123.top + 1 };
const box789 = await getRichTextBoundingBox(page, '4');
const inside789 = { x: box789.right - 1, y: box789.bottom - 1 };
@@ -200,10 +200,10 @@ test('native range selection backwards', async ({ page }) => {
await assertRichTexts(page, ['123', '456', '789']);
const box123 = await getRichTextBoundingBox(page, '2');
const above123 = { x: box123.left, y: box123.top - 2 };
const above123 = { x: box123.left + 1, y: box123.top + 1 };
const box789 = await getRichTextBoundingBox(page, '4');
const bottomRight789 = { x: box789.right, y: box789.bottom };
const bottomRight789 = { x: box789.right - 1, y: box789.bottom - 1 };
// from bottom to top
await dragBetweenCoords(page, bottomRight789, above123, { steps: 10 });
@@ -230,7 +230,7 @@ test('native range selection backwards by forwardDelete', async ({ page }) => {
const above123 = { x: box123.left, y: box123.top - 2 };
const box789 = await getRichTextBoundingBox(page, '4');
const bottomRight789 = { x: box789.right, y: box789.bottom };
const bottomRight789 = { x: box789.right - 1, y: box789.bottom - 1 };
// from bottom to top
await dragBetweenCoords(page, bottomRight789, above123, { steps: 10 });
@@ -390,7 +390,7 @@ test('select all text with dragging and delete', async ({ page }) => {
await initThreeParagraphs(page);
await assertRichTexts(page, ['123', '456', '789']);
await dragBetweenIndices(page, [0, 0], [2, 3], undefined, undefined, {
await dragBetweenIndices(page, [0, 0], [2, 3], { x: 1, y: 1 }, undefined, {
steps: 20,
});
await pressBackspace(page);
@@ -434,14 +434,7 @@ test('select all text with keyboard delete', async ({ page }) => {
await selectAllByKeyboard(page);
await selectAllByKeyboard(page);
await pressBackspace(page);
await assertRichTexts(page, ['', '456', '789']);
await type(page, 'abc');
await selectAllByKeyboard(page);
await selectAllByKeyboard(page);
await selectAllByKeyboard(page);
await pressBackspace(page);
await assertRichTexts(page, ['']);
await assertRichTexts(page, ['456', '789']);
});
test('select text leaving a few words in the last line and delete', async ({
@@ -801,7 +794,7 @@ test('Delete the second divider between two dividers by forwardDelete', async ({
await pressArrowUp(page);
await pressForwardDelete(page);
await assertDivider(page, 1);
await assertRichTexts(page, ['', '', '']);
await assertRichTexts(page, ['', '']);
});
test('should delete line with content after divider not lose content', async ({
@@ -818,7 +811,7 @@ test('should delete line with content after divider not lose content', async ({
await waitNextFrame(page);
await pressBackspace(page, 2);
await assertDivider(page, 0);
await assertRichTexts(page, ['', '123']);
await assertRichTexts(page, ['123']);
});
test('should forwardDelete divider works properly', async ({ page }) => {
@@ -835,7 +828,7 @@ test('should forwardDelete divider works properly', async ({ page }) => {
await page.keyboard.press(`${SHORT_KEY}+ArrowRight`, { delay: 50 });
await pressForwardDelete(page);
await assertDivider(page, 0);
await assertRichTexts(page, ['123', '', '']);
await assertRichTexts(page, ['123', '']);
});
test('the cursor should move to closest editor block when clicking outside container', async ({