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

How to keep formatting between lines? #5620

Closed
nickschinestzki opened this issue Feb 17, 2024 · 7 comments · Fixed by #5822 or #5900 · May be fixed by Opetushallitus/kouta-ui#574
Closed

How to keep formatting between lines? #5620

nickschinestzki opened this issue Feb 17, 2024 · 7 comments · Fixed by #5822 or #5900 · May be fixed by Opetushallitus/kouta-ui#574
Assignees

Comments

@nickschinestzki
Copy link

I'm trying to achieve a different behavior regarding the formatting between lines in the Lexical Editor.

The current behavior

  1. In an empty editor, the user starts adding formatting and styles in the editor (font-family, font-size, color, bold, italic, etc)
  2. When you press Enter once, it will insert a new line, which will have an "unstyled cursor" but upon new typing, the styles and formatting are applied again to the text.
  3. When you press Enter twice, the new line, separated by the other ones, will lose all of the previous formatting and styling, returning to the default.
Gravacao.de.Tela.2024-02-16.as.09.16.21.mov

The desired behavior

  1. In an empty editor, the user starts adding formatting and styles in the editor (font-family, font-size, color, bold, italic, etc)
  2. When pressing Enter regarding of how much times/lines, the styles and formats are preserved. The user doesn't have to select the font-family and font-size again (for example) every time he creates a new a paragraph.

How can I achieve this?

Originally posted by @nickschinestzki in #5619

@moy2010
Copy link
Contributor

moy2010 commented Feb 18, 2024

It sounds like you'll need to prevent the stop the propagation of the Enter button event (check Lexical's command pattern), and handle yourself the creation of new paragraph nodes to conserve the existing state.

@ivailop7
Copy link
Collaborator

@acywatson @zurfyx do we agree, this should be the default behaviour?

@acywatson
Copy link
Contributor

@acywatson @zurfyx do we agree, this should be the default behaviour?

I mean the trade off is now that you have the opposite problem. If a user wants to just bold one line or add several formats to one segment of text, they need to then clear all those formats off when they start typing on the next line.

I suspect the case of adding formats to a small portion of otherwise non-formatted text (or even typing the text non-formatted, then going back to apply formats to specific sections) is far more common than the case of setting a bunch of formats and typing multiple lines with those formats engaged.

Probably the perspective we should come from here, though, is what's the easiest way to set it up so a developer can easily customize it for their own editor. From that angle, I think it might be better to make the formats sticky, and allow people to write a plugin that clears the formatting on enter or on double-enter, as they see fit.

Additionally, though, this would be a breaking change.

@nickschinestzki
Copy link
Author

I have discovered that using Shift + Enter results in the exact behavior I'm searching for. I'm having difficulties to formulate this into a Plugin, that would not require the user to keep pressing Shift to make it work.

@maliuta-oleksandr
Copy link

the same. it should follow the same styling.

@vect-spasquereau
Copy link
Contributor

I have discovered that using Shift + Enter results in the exact behavior I'm searching for. I'm having difficulties to formulate this into a Plugin, that would not require the user to keep pressing Shift to make it work.

I'm facing the same issue, see discord thread 🙂

@vect-spasquereau
Copy link
Contributor

thank you very much @Sahejkm 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment