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

pasting text on input was creating a new paragraph node instead of ad… #4246

Merged
merged 6 commits into from
Apr 3, 2023

Conversation

khanakia
Copy link
Contributor

When pasting the text on input was not working it was created a new paragraph node

check reference issue:

#4086

@vercel
Copy link

vercel bot commented Mar 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2023 8:10am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2023 8:10am

@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 Mar 30, 2023
@khanakia
Copy link
Contributor Author

@zurfyx I am unable to understand why integrity check is failed at flow test when i run locally i do not see any error

➜  lexical git:(paste_input) ✗ node ./scripts/check-flow-types.js

Running Flow...
No errors!

Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Thank you, that's a tricky one. Let me come back to you tomorrow, I want to think this through. I think that the approach we want to take here is to handle DecoratorNode separately/or a reusable component that handles the basic events for you automatically. Right now we can work around this by handling the click event manually inside the DecoratorNode, like we do with images, and we could do the same thing with equation but it's not very scalable.

For reference https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/nodes/ImageComponent.tsx#L226

@khanakia
Copy link
Contributor Author

Thank you, that's a tricky one. Let me come back to you tomorrow, I want to think this through. I think that the approach we want to take here is to handle DecoratorNode separately/or a reusable component that handles the basic events for you automatically. Right now we can work around this by handling the click event manually inside the DecoratorNode, like we do with images, and we could do the same thing with equation but it's not very scalable.

For reference https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/nodes/ImageComponent.tsx#L226

I do quite understand how to make the paste work inside the INPUTS as I have shown in the video POLL Component in case.

I do not see any way to make the logic work with the CLICK_COMMAND as you suggested

Screen.Recording.2023-03-30.at.8.57.46.PM.mov

@zurfyx
Copy link
Member

zurfyx commented Mar 31, 2023

You're right, my answer yesterday wasn't very accurate. To understand this problem better I believe we have to evaluate the use cases of Decorator + Paste.

  1. Paste when the Node is selected
  2. Paste when multiple Nodes are selected
  3. Paste when you're interacting with the Decorator

The audience who understand the 1 and 2 better is the editor itself that hosts the selection. We can delegate this work to it. This is already done even though it doesn't fully work.

Third is the conflicting case you are trying to solve. The constraint here is that Lexical doesn't understand Decorator Nodes, so that is someting that you the Decorator Node will have to handle itself, either in a generic or non-generic manner.

I'm not sure what the generic solution would look like for now but for we can have something like this to fix polls.

PollComponent.tsx

 editor.registerCommand(
      PASTE_COMMAND,
     () => {
      if (inputIsFocused) {
        return true;
      }
...

That is in a way the same thing that image captions do but the event is handled for you as it's part of the Lexical Rich Text plugin setup.

@khanakia
Copy link
Contributor Author

Thank i was able to do something like that already.

But is there no way we handle this globally instead of handling every Decorated Component?

I see other editors like slatejs, editorjs also handle it globally, and the same solution i proposed with a pull request.

@zurfyx
Copy link
Member

zurfyx commented Mar 31, 2023

Your solution is correct. My concern is around trying to make the upper layer smart and trying to understand DecoratorNodes which it will never be able to in a good way. For example, if your DecoratorNode was instead a DropZone that handled paste this would never handle it. Should this be handled inside the PlainText plugin too?

@fantactuka
Copy link
Contributor

Can we reuse isSelectionWithinEditor or isSelectionCapturedInDecoratorInput here?

@khanakia
Copy link
Contributor Author

I do not this is meant for plain text i have studied so many sites using lexical hardly anybody uses plain text with decorated nodes has input.

Plain text is mainly to build the minimal interface.

I am all ears if we have to we can

@zurfyx
Copy link
Member

zurfyx commented Mar 31, 2023

Discussed this PR as a team, happy to merge after @fantactuka's comment is addressed, this would decrease the overall added bundle size. Thank you for working on this!

@khanakia
Copy link
Contributor Author

khanakia commented Apr 1, 2023

I have updated the code

Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Thank you for iterating on this!

@zurfyx zurfyx merged commit 8cfe656 into facebook:main Apr 3, 2023
@acywatson acywatson mentioned this pull request Apr 14, 2023
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.

4 participants