hey icon indicating copy to clipboard operation
hey copied to clipboard

fix: remove paragraphs from editor

Open foolo opened this issue 2 years ago β€’ 9 comments

What does this PR do?

Fixes new problem as described in comment https://github.com/lensterxyz/lenster/issues/1193#issuecomment-1420805409

This works by modifying the editor's content tree, replacing all paragraphs with newlines, before the content is exported to markdown

See also https://lexical.dev/docs/concepts/editor-state#updating-state

Type of change

  • [x] Bug fix (non-breaking change which fixes an issue)

How should this be tested?

  • Open publication editor, paste the content below and publish the post
aaaaaa
bbbb

foo
bar
  • Verify that the published post looks the same

  • Repeat the above steps, but typing the content by hand, instead of pasting it

foolo avatar Feb 08 '23 11:02 foolo

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

πŸ’‘Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

height[bot] avatar Feb 08 '23 11:02 height[bot]

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated
api βœ… Ready (Inspect) Visit Preview πŸ’¬ Add your feedback Feb 15, 2023 at 9:07AM (UTC)
prerender βœ… Ready (Inspect) Visit Preview πŸ’¬ Add your feedback Feb 15, 2023 at 9:07AM (UTC)
web βœ… Ready (Inspect) Visit Preview πŸ’¬ Add your feedback Feb 15, 2023 at 9:07AM (UTC)

vercel[bot] avatar Feb 08 '23 11:02 vercel[bot]

Looks too complex :(

bigint avatar Feb 09 '23 16:02 bigint

Looks too complex :(

@bigint Yeah, I agree it is a bit complex. But on the other hand it's the only solution so far that actually works πŸ™‚ It's not for me to decide whether it's too complex though. We could also try to think of a new, different solution.

foolo avatar Feb 09 '23 16:02 foolo

cc @harish-sethuraman πŸ™‡πŸΌ

bigint avatar Feb 13 '23 10:02 bigint

Isn't this solved yet (I remember replacing two line feed with one)? I don't think we have to deal with this given that lexical is having \n\n as block separator?

their code here: https://github.com/facebook/lexical/blob/3228323a2e32245386dacc0327d844de6390e5a6/packages/lexical-markdown/src/MarkdownExport.ts#L55

harish-sethuraman avatar Feb 13 '23 18:02 harish-sethuraman

Isn't this solved yet (I remember replacing two line feed with one)? I don't think we have to deal with this given that lexical is having \n\n as block separator?

their code here: https://github.com/facebook/lexical/blob/3228323a2e32245386dacc0327d844de6390e5a6/packages/lexical-markdown/src/MarkdownExport.ts#L55

The above fix (replacing \n\n with \n) unfortunately introduced a new error: when making an empty line by hand, that empty line disappeared

@bigint did remove that fix again after an update of Lexical, after which the problem was believed to be gone, but it turned out it wasn't.

However, now there is a new problem, as described in comment: https://github.com/lensterxyz/lenster/issues/1193#issuecomment-1420805409 Try it :) This PR fixes the problem.

foolo avatar Feb 13 '23 19:02 foolo

I see that when I used the notes app in Mac to copy paste the following two new lines appeared instead of one in your PR. But when I copied from github it works fine. We need to fix that as well? we dont want two new lines instead of one while pasting from notes? We might want

Paste
This
And

See
magic

From what I found is when we copy paste from notes app we get an line break node Screenshot 2023-02-14 at 1 03 19 PM

If we use some other app we dont get that Screenshot 2023-02-14 at 1 02 14 PM

harish-sethuraman avatar Feb 14 '23 07:02 harish-sethuraman

@harish-sethuraman Thanks for testing! Agree, the new bug you found is not good. We can probably tweak this PR to cover that case. But, of course, this is not really a long term solution, since it's quite hackish, and there's a big chance that even more bugs will show up for all kinds of tricky cases.

I discussed with @bigint before about that the long-term solution is to use Lexical also for rendering (in read-only mode), which will be even more necessary if we want to support editing of existing posts.

foolo avatar Feb 14 '23 08:02 foolo

I'm closing this for now, we might move to slate js asap πŸ™‡πŸΌ

bigint avatar Mar 24 '23 15:03 bigint