Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Fix $transferStartingElementPointToTextPoint() #4756 #5094

Merged
merged 1 commit into from
Oct 10, 2023
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
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