From 85fb8673e2228c945ab3dc337a8c43d2e749d8f0 Mon Sep 17 00:00:00 2001 From: John Flockton Date: Tue, 10 Oct 2023 13:29:46 +0100 Subject: [PATCH] Revert Fix $transferStartingElementPointToTextPoint() #4756 (#5094) --- packages/lexical/src/LexicalSelection.ts | 11 ----- .../__tests__/unit/LexicalSelection.test.ts | 48 +------------------ 2 files changed, 1 insertion(+), 58 deletions(-) diff --git a/packages/lexical/src/LexicalSelection.ts b/packages/lexical/src/LexicalSelection.ts index 919457e3789..7d8cba64d47 100644 --- a/packages/lexical/src/LexicalSelection.ts +++ b/packages/lexical/src/LexicalSelection.ts @@ -244,17 +244,6 @@ function $transferStartingElementPointToTextPoint( element.append(target); } else { placementNode.insertBefore(target); - // Fix the end point offset if it refers to the same element as start, - // as we've now inserted another element before it. Note that we only - // do it if selection is not collapsed as otherwise it'll transfer - // both focus and anchor to the text node below - if ( - end.type === 'element' && - end.key === start.key && - end.offset !== start.offset - ) { - end.set(end.key, end.offset + 1, 'element'); - } } // Transfer the element point to a text point. if (start.is(end)) { diff --git a/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts b/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts index e97b4d8514b..e9949792dbe 100644 --- a/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts +++ b/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts @@ -9,14 +9,13 @@ import {$createLinkNode} from '@lexical/link'; import { $createParagraphNode, - $createRangeSelection, $createTextNode, $getRoot, LexicalEditor, RangeSelection, } from 'lexical'; -import {$createTestDecoratorNode, initializeUnitTest} from '../utils'; +import {initializeUnitTest} from '../utils'; describe('LexicalSelection tests', () => { initializeUnitTest((testEnv) => { @@ -323,51 +322,6 @@ describe('LexicalSelection tests', () => { // await insertText({container, editor, method: 'insertNodes'}); // }); }); - - describe('transferStartingElementPointToTextPoint', () => { - test('transferStartingElementPointToTextPoint', async () => { - const {container, editor} = testEnv; - - if (!container) { - throw new Error('Expected container to be truthy'); - } - - await editor.update(() => { - const root = $getRoot(); - if (root.getFirstChild() !== null) { - throw new Error('Expected root to be childless'); - } - - const paragraph = $createParagraphNode(); - const text = $createTextNode('Text'); - const image = $createTestDecoratorNode(); - paragraph.append(text, image); - - root.append(paragraph); - - expect(root.getTextContent()).toEqual('TextHello world'); - - const decoratorIndexInParent = image.getIndexWithinParent(); - const paragraphKey = paragraph.getKey(); - - const selection = $createRangeSelection(); - selection.anchor.set( - paragraphKey, - decoratorIndexInParent, - 'element', - ); - selection.focus.set( - paragraphKey, - decoratorIndexInParent + 1, - 'element', - ); - - selection.insertText('A'); - - expect(root.getTextContent()).toEqual('TextA'); - }); - }); - }); }); }); });