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

core: add OutlineTextNode splitText with selection tests #121

Merged
merged 2 commits into from
Feb 22, 2021

Conversation

yangshun
Copy link
Contributor

@yangshun yangshun commented Feb 21, 2021

Summary

Follow up of #118, where we add splitText() with current selections.

Test Plan

Tests added.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 21, 2021
focusOffset: 2,
},
],
[
Copy link
Contributor Author

@yangshun yangshun Feb 21, 2021

Choose a reason for hiding this comment

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

This test is failing and I'd like to clarify the correct behavior before proceeding further - When a text is split into 3 chunks, should the start and end of the selection fall on the first and the third chunk respectively?

For example, intuitively, when a selection is split like this, the anchor and focus should be on the first and third node respectively?

"Hello World" -> "Hell" "o " "World"
   ^^^^^^           ^^   ^^   ^^

The current behavior is that the focus is on the second node with an offset of 4. Not sure if intended or a bug.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is definitely a bug! Nice one catching it. I suspected that this logic might have been a bit fragile and this text confirms it :)

This makes sense as to why I was running into issues with some of the www plugins and had to manually select the node after, which seemed it a bit strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, I'll follow up and fix it in this PR!

Copy link
Contributor Author

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Ready for review!

@@ -119,14 +119,13 @@ function splitText(
const sibling = getWritableNode(createTextNode(part));
sibling.__flags = flags;
const siblingKey = sibling.__key;
const nextTextSize = textLength + partSize;
const nextTextSize = textSize + partSize;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the bug is here.


if (selection !== null) {
const anchorOffset = selection.anchorOffset;
const focusOffset = selection.focusOffset;

if (
selection !== null &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Safe to remove since L124 checks this

@yangshun yangshun merged commit ee6ace9 into main Feb 22, 2021
@trueadm trueadm deleted the yangshun/text-node-split-select branch February 22, 2021 15:23
acywatson pushed a commit that referenced this pull request Apr 9, 2022
* core: add OutlineTextNode splitText with selection tests

* core: fix core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants