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

When pressing Enter in an H3 or other non-default text element, inline styles should not carry forward to the new paragraph tag that follows #4538

Closed
nicholasbester opened this issue May 15, 2024 · 10 comments
Labels

Comments

@nicholasbester
Copy link

nicholasbester commented May 15, 2024

Applies to ApostropheCMS 4.2.3

To Reproduce

Step by step instructions to reproduce the behavior:

Ensure you have a styles within your rich text widget include inline styles effecting spans:

styles: [
    {
      tag: 'h1',
      label: 'Heading (h1)'
    },
    {
      tag: 'p',
      label: 'Paragraph (P)'
    },
    {
      tag: 'span',
      label: 'Highlight Orange (Span)',
      class: 'orange'
    }
  ]
  1. Add a rich text area on the display
  2. Set the text style to a heading tag (h1 etc...) and type out a basic heading
  3. Highlight the heading and add inline styles. (In my case this is setting "Highlight Orange (Span)" the "orange" class)
  4. Once this is added, press the "Enter" key on the keyboard which takes you to the new line
  5. Typing on the new line retains the inline styles

Expected behavior

The expected behaviour is that the highlighted span shouldn't exist on the next line after "Enter" is pressed and it should revert to a default format

Describe the bug

In most rich text editors, once a user presses the enter key, they are exiting the formatting of the previous line to start a newly formatted line.

Details

Version of Node.js:
v20.13.1

Server Operating System:
MacOS X for local development and running on ApostropheCMS for staging and production

Additional context:
Happens in Google Chrome but I think this is specific to the editor. Running latest ApostropheCMS 4.2.3

Screenshots
Screenshot 2024-05-15 at 13 51 04
Adding text to the display and setting it to be highlighted in orange

Screenshot 2024-05-15 at 13 51 27
Pressing the "Enter" key takes me to the new line and essentially I should outside of the span of the previous line

Video
https://github.com/apostrophecms/apostrophe/assets/1872093/f8e94170-83f7-4048-bb6b-4cab8d75d195

@boutell boutell removed the bug label May 15, 2024
@boutell
Copy link
Member

boutell commented May 15, 2024

Hi Nick,

I was surprised by this report because I don't see this behavior in google docs, word, etc. If you apply an inline style then you have that style continuously even if you press enter and keep typing on a new line etc. I think this is the behavior that tiptap is designed to emulate. So I'm going to remove the bug label.

I am curious though to know which editors behave as you describe. It's possible this is an area where users may have varying preferences that could be supported.

@nicholasbester
Copy link
Author

This generally happens when you have a heading and you're applying the highlight to that heading text and then press enter which converts you to paragraph format. In MS Word, if you type out a Heading 1, then change the colour, followed by pressing enter, you'll be switched back to the default colour.

It's a specific edge case I guess...
Screenshot 2024-05-15 at 15 04 19

@boutell
Copy link
Member

boutell commented May 15, 2024

I see what you mean. Google Docs works this way too. However if you start out in ordinary text mode and hit enter it keeps the current inline style. The change occurs only when you transition to a different block element.

I think this is a reasonable feature request and a possible area for a community contribution. Might be an optional behavior. Curious what @stuartromanek and @BoDonkey think.

@BoDonkey
Copy link
Contributor

BoDonkey commented May 15, 2024

Not sure if you meant me @boutell! I have to say that I would expect the behavior shown in the screenshot. Instead, if you go from a heading with a span adding inline styling to a new paragraph by hitting return you end up with something like <h3><span class="red">My Title</span></h3><p><span class="red">My paragraph</span></p> which is a little odd. I would expect a plain p tag.
Reasonable request for a community contribution.

@boutell
Copy link
Member

boutell commented May 15, 2024

Good to have another take! And of course the fact that Word and Docs both do it is a big point in favor.

@stuartromanek
Copy link
Member

Generally I think what is happening is the correct behavior, the inline style following the line break.

@nicholasbester and @BoDonkey you are both describing a different behavior, one which resets any inline selections at the close of a block, which I think is reasonable and actually what MSWord and GDocs are implementing.

I do lean more towards labeling that a bug

@boutell boutell added the bug label May 15, 2024
@boutell boutell changed the title Inline styles not escaping after return When pressing Enter in an H3 or other non-default text element, inline styles should not carry forward to the new paragraph tag that follows May 15, 2024
@boutell
Copy link
Member

boutell commented May 15, 2024

Nick I updated the title and restored the "bug" label, would you please update your example in the description so that it clearly involves transitioning from a heading? The existing example just has paragraphs, and in that situation it's correct behavior.

@stuartromanek
Copy link
Member

Got a fix cookin' #4541 @nicholasbester @boutell @BoDonkey

@nicholasbester
Copy link
Author

@boutell description updated :)

@stuartromanek
Copy link
Member

merged #4541

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants