fix(editor): behavior of deleting at the start of line (#12787)

Close BS-3182, #12736 




#### PR Dependency Tree


* **PR #12787** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved the behavior when deleting empty lines and merging blocks,
ensuring more accurate handling of block deletion and cursor focus in
various scenarios.
- **Tests**
- Added new end-to-end tests to verify correct deletion of lines in
edgeless text and paragraph blocks, including checks for block removal
and cursor position.
- Introduced a utility function to retrieve block IDs for testing
purposes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
L-Sun
2025-06-12 14:58:03 +08:00
committed by GitHub
parent d12954f8c3
commit 8d2214424c
4 changed files with 138 additions and 16 deletions

View File

@@ -8,7 +8,9 @@ import {
enterPlaygroundRoom,
focusRichText,
focusTitle,
getBlockIds,
getIndexCoordinate,
getInlineSelectionIndex,
getPageSnapshot,
initEmptyEdgelessState,
initEmptyParagraphState,
@@ -44,6 +46,7 @@ import {
assertBlockChildrenIds,
assertBlockCount,
assertBlockSelections,
assertBlockTextContent,
assertBlockType,
assertClassName,
assertDivider,
@@ -734,6 +737,45 @@ test('delete at start of paragraph with content', async ({ page }) => {
await assertRichTexts(page, ['123', '456']);
});
test('delete empty line should work correctly', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyParagraphState(page);
await focusRichText(page);
// 2: aaa
// 3: bbb
// 4: ccc|
{
await type(page, 'aaa');
await pressEnter(page);
await pressTab(page);
await type(page, 'bbb');
await pressEnter(page);
await pressShiftTab(page);
await type(page, 'ccc');
}
// 2: aaa
// 3: bbb|
await pressBackspace(page, 4);
expect(await getBlockIds(page)).not.toContain(4);
await assertBlockTextContent(page, 2, 'aaa');
await assertBlockTextContent(page, 3, 'bbb');
expect(await getInlineSelectionIndex(page)).toBe(3);
// title: |aaa
// 3: bbb
{
await pressArrowUp(page);
await pressArrowLeft(page, 3);
await pressBackspace(page);
}
await expect(page.locator('doc-title')).toContainText('aaa');
expect(await getBlockIds(page)).not.toContain(2);
await assertBlockTextContent(page, 3, 'bbb');
expect(await getInlineSelectionIndex(page)).toBe(0);
});
test('get focus from page title enter', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyParagraphState(page);