Skip to content

Commit

Permalink
Revert Fix $transferStartingElementPointToTextPoint() #4756 (#5094)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegreatercurve authored Oct 10, 2023
1 parent 9a679ec commit 85fb867
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
11 changes: 0 additions & 11 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
48 changes: 1 addition & 47 deletions packages/lexical/src/__tests__/unit/LexicalSelection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
});
});
});
});
});
});
Expand Down

2 comments on commit 85fb867

@vercel
Copy link

@vercel vercel bot commented on 85fb867 Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical-git-main-fbopensource.vercel.app
lexical.dev
lexicaljs.org
www.lexical.dev
lexical-fbopensource.vercel.app
lexicaljs.com

@vercel
Copy link

@vercel vercel bot commented on 85fb867 Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground.vercel.app
playground.lexical.dev
lexical-playground-git-main-fbopensource.vercel.app
lexical-playground-fbopensource.vercel.app

Please sign in to comment.