Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/core/src/extensions/Blocks/nodes/BlockContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,19 @@ export const BlockContainer = Node.create<IBlock>({
}

// Deletes next block and adds its text content to the nearest previous block.
// TODO: Use slices.

if (dispatch) {
state.tr.deleteRange(startPos, startPos + contentNode.nodeSize);
state.tr.insertText(contentNode.textContent, prevBlockEndPos - 1);
dispatch(
state.tr
.deleteRange(startPos, startPos + contentNode.nodeSize)
.replace(
prevBlockEndPos - 1,
startPos,
new Slice(contentNode.content, 0, 0)
)
.scrollIntoView()
);

state.tr.setSelection(
new TextSelection(state.doc.resolve(prevBlockEndPos - 1))
);
Expand Down
56 changes: 55 additions & 1 deletion tests/end-to-end/keyboardhandlers/keyboardhandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
H_TWO_BLOCK_SELECTOR,
} from "../../utils/const";
import { compareDocToSnapshot, focusOnEditor } from "../../utils/editor";
import { insertHeading } from "../../utils/copypaste";
import { insertHeading, insertParagraph } from "../../utils/copypaste";

test.describe.configure({ mode: "serial" });

Expand Down Expand Up @@ -72,4 +72,58 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {

await compareDocToSnapshot(page, "enterPreservesNestedBlocks.json");
});
test("Check Backspace at the start of a block", async ({ page }) => {
await focusOnEditor(page);
await insertHeading(page, 1);

await page.keyboard.press("ArrowUp");
await page.keyboard.press("Control+ArrowLeft");
await page.keyboard.press("Backspace");

await compareDocToSnapshot(page, "backspaceStartOfBlock.json");
});
test("Check Backspace preserves marks", async ({ page }) => {
await focusOnEditor(page);
await insertParagraph(page);
await insertParagraph(page);

await page.keyboard.press("ArrowUp");
await page.keyboard.press("Control+ArrowLeft");

for (let i = 0; i < 2; i++) {
await page.keyboard.press("ArrowRight");
}

for (let i = 0; i < 5; i++) {
await page.keyboard.press("Shift+ArrowRight");
}

await page.locator(ITALIC_BUTTON_SELECTOR).click();
await page.waitForTimeout(500);

await page.keyboard.press("ArrowLeft");
await page.keyboard.press("Control+ArrowLeft");
await page.keyboard.press("Backspace");

await compareDocToSnapshot(page, "backspacePreservesMarks.json");
});
test("Check Backspace preserves nested blocks", async ({ page }) => {
await focusOnEditor(page);
await insertParagraph(page);
await insertParagraph(page);
await page.keyboard.press("Tab");
await insertParagraph(page);
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await insertParagraph(page);

for (let i = 0; i < 3; i++) {
await page.keyboard.press("ArrowUp");
}

await page.keyboard.press("Control+ArrowLeft");
await page.keyboard.press("Backspace");

await compareDocToSnapshot(page, "backspacePreservesNestedBlocks.json");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"type": "doc",
"content": [
{
"type": "blockGroup",
"content": [
{
"type": "blockContainer",
"attrs": {
"id": "0",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
},
"content": [
{
"type": "text",
"text": "ParagraphPa"
},
{
"type": "text",
"marks": [
{
"type": "italic"
}
],
"text": "ragra"
},
{
"type": "text",
"text": "ph"
}
]
}
]
},
{
"type": "blockContainer",
"attrs": {
"id": "2",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"type": "doc",
"content": [
{
"type": "blockGroup",
"content": [
{
"type": "blockContainer",
"attrs": {
"id": "0",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
},
"content": [
{
"type": "text",
"text": "ParagraphPa"
},
{
"type": "text",
"marks": [
{
"type": "italic"
}
],
"text": "ragra"
},
{
"type": "text",
"text": "ph"
}
]
}
]
},
{
"type": "blockContainer",
"attrs": {
"id": "2",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"type": "doc",
"content": [
{
"type": "blockGroup",
"content": [
{
"type": "blockContainer",
"attrs": {
"id": "0",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
},
"content": [
{
"type": "text",
"text": "ParagraphPa"
},
{
"type": "text",
"marks": [
{
"type": "italic"
}
],
"text": "ragra"
},
{
"type": "text",
"text": "ph"
}
]
}
]
},
{
"type": "blockContainer",
"attrs": {
"id": "2",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"type": "doc",
"content": [
{
"type": "blockGroup",
"content": [
{
"type": "blockContainer",
"attrs": {
"id": "0",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
},
"content": [
{
"type": "text",
"text": "ParagraphParagraph"
}
]
}
]
},
{
"type": "blockContainer",
"attrs": {
"id": "2",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
},
"content": [
{
"type": "text",
"text": "Paragraph"
}
]
},
{
"type": "blockGroup",
"content": [
{
"type": "blockContainer",
"attrs": {
"id": "3",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
},
"content": [
{
"type": "text",
"text": "Paragraph"
}
]
}
]
}
]
}
]
},
{
"type": "blockContainer",
"attrs": {
"id": "4",
"textColor": "default",
"backgroundColor": "default"
},
"content": [
{
"type": "paragraph",
"attrs": {
"textAlignment": "left"
}
}
]
}
]
}
]
}
Loading