Skip to content

Commit

Permalink
Adjustments on top of #3840
Browse files Browse the repository at this point in the history
  • Loading branch information
fantactuka committed Apr 28, 2023
1 parent 28fec90 commit aabb5b6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
71 changes: 69 additions & 2 deletions packages/lexical-playground/__tests__/e2e/Selection.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import {
deleteBackward,
deleteForward,
moveLeft,
moveRight,
Expand Down Expand Up @@ -274,11 +275,11 @@ test.describe('Selection', () => {
test('Can select all with node selection', async ({page, isPlainText}) => {
test.skip(isPlainText);
await focusEditor(page);
await page.keyboard.type('Text before');
await page.keyboard.type('# Text before');
await insertSampleImage(page);
await page.keyboard.type('Text after');
await selectAll(page);
await page.keyboard.press('Delete');
await deleteBackward(page);
await assertHTML(
page,
html`
Expand Down Expand Up @@ -353,4 +354,70 @@ test.describe('Selection', () => {
`,
);
});

test('Can delete block elements', async ({page, isPlainText}) => {
test.skip(isPlainText);
await focusEditor(page);
await page.keyboard.type('# A');
await page.keyboard.press('Enter');
await page.keyboard.type('b');
await assertHTML(
page,
html`
<h1
class="PlaygroundEditorTheme__h1 PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">A</span>
</h1>
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">b</span>
</p>
`,
);
await moveLeft(page, 2);

await deleteBackward(page);
await assertHTML(
page,
html`
<h1 class="PlaygroundEditorTheme__h1">
<br />
</h1>
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">b</span>
</p>
`,
);

await deleteBackward(page);
await assertHTML(
page,
html`
<p class="PlaygroundEditorTheme__paragraph">
<br />
</p>
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">b</span>
</p>
`,
);

await deleteBackward(page);
await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">b</span>
</p>
`,
);
});
});
2 changes: 1 addition & 1 deletion packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,7 @@ export class RangeSelection implements BaseSelection {
}

deleteCharacter(isBackward: boolean): void {
const wasCollapsed = this.isCollapsed();
if (this.isCollapsed()) {
const anchor = this.anchor;
const focus = this.focus;
Expand Down Expand Up @@ -2122,7 +2123,6 @@ export class RangeSelection implements BaseSelection {
}
}
}
const wasCollapsed = this.isCollapsed();
this.removeText();
if (
isBackward &&
Expand Down

0 comments on commit aabb5b6

Please sign in to comment.