Skip to content

Commit e37d040

Browse files
Fix forward delete before tables
1 parent f18cff5 commit e37d040

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
$getRoot,
2626
$getSelection,
2727
$isParagraphNode,
28+
$isRangeSelection,
2829
$isTextNode,
2930
$setSelection,
3031
} from 'lexical';
@@ -166,5 +167,27 @@ describe('table selection', () => {
166167
});
167168
});
168169
});
170+
171+
describe('regression #8075', () => {
172+
test('forward delete removes an empty paragraph before a table', () => {
173+
testEnv.editor.update(
174+
() => {
175+
const root = $getRoot();
176+
const paragraph = $createParagraphNode();
177+
root.clear().append(paragraph, tableNode);
178+
paragraph.select();
179+
180+
const selection = $getSelection();
181+
if (!$isRangeSelection(selection)) {
182+
throw new Error('Expected range selection');
183+
}
184+
selection.deleteCharacter(false);
185+
186+
expect(root.getChildren()).toEqual([tableNode]);
187+
},
188+
{discrete: true},
189+
);
190+
});
191+
});
169192
});
170193
});

packages/lexical/src/LexicalSelection.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,18 @@ export class RangeSelection implements BaseSelection {
17481748
(parent === null ? null : parent.getNextSibling());
17491749

17501750
if ($isElementNode(nextSibling) && nextSibling.isShadowRoot()) {
1751+
if (
1752+
anchor.type === 'element' &&
1753+
$isElementNode(anchorNode) &&
1754+
anchorNode.isEmpty()
1755+
) {
1756+
const caret = $normalizeCaret($getChildCaret(nextSibling, 'next'));
1757+
$updateRangeSelectionFromCaretRange(
1758+
this,
1759+
$getCaretRange(caret, caret),
1760+
);
1761+
anchorNode.remove();
1762+
}
17511763
return true;
17521764
}
17531765
}

0 commit comments

Comments
 (0)