Hide Details applies separately to each paragraph

AI-generated summary

Hide Details applies separately to each paragraph

Silvanus reported a bug in the details-plugin where selecting a large chunk of text separated by paragraphs and clicking the “Hide Details” button results in each paragraph being prefixed with [details...] instead of applying it to the entire selection. This issue also affects the spoiler-plugin.

The problem is suspected to be in the applySurround function in the apply-details.js.es6 file. To reproduce the issue, select multiple lines of text, choose all the lines, and click “Hide Details.” The result is multiple [details=Summary] blocks instead of a single block.

jomaxro provided an example of the markdown generated by this issue. codinghorror acknowledged the issue and tagged @tgxworld to fix it. tgxworld created a PR to address the issue and requested feedback from eviltrout before merging. The PR was eventually merged, resolving the issue.

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

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

Aha we should fix this @tgxworld

「いいね!」 1

PR in

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

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

「いいね!」 4

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

「いいね!」 5