Hide Details applies separately to each paragraph

Description

Hi, there’s a bug with details-plugin: when selecting a big chunk of text separated in paragraphs, clicking the Hide Details -button causes the [details...] to be prefixed to each separate paragraph, not just the beginning (and end) of the selection.

The same bug applies to spoiler-plugin.

Location of bug

As far as I know, the problem is here (no idea how to fix):

https://github.com/discourse/discourse/blob/master/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6#L14-L22

So likely the culprit is applySurround and how it functions…

Reproduction

  1. Write several lines of text (separate with linebreak)
  2. Choose all the lines.
  3. Click Hide Details.
  4. PROFIT

Result

Summary

Lines with text

Summary

Lines with text

Summary

Lines with text

Summary

Lines with text

Summary

Lines with text

[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]

Should result in:

[details=Summary]Lines with text
Lines with text
Lines with text
Lines with text
Lines with text[/details]

[details=Summary]Lines with text
Lines with text
Lines with text
Lines with text
Lines with text[/details]
3 Likes

For reference, this is the markdown that selecting multiple lines and clicking hide details generates.

[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]

Thanks, I edited this into the first message!

1 Like

Aha we should fix this @tgxworld

1 Like

PR in

https://github.com/discourse/discourse/pull/4499

Would love to get @eviltrout’s thoughts first before merging :slight_smile:

4 Likes

I said it was cool via chat, and it looks like the PR was merged. Thanks @tgxworld!

5 Likes