diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/lang/formatter/MarkdownSpacingBuilder.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/lang/formatter/MarkdownSpacingBuilder.kt index 54dec7d25551..b2dd90dd6e0c 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/lang/formatter/MarkdownSpacingBuilder.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/lang/formatter/MarkdownSpacingBuilder.kt @@ -83,7 +83,7 @@ internal object MarkdownSpacingBuilder { .apply { val spaces = if (markdown.FORCE_ONE_SPACE_BETWEEN_WORDS) 1 else Integer.MAX_VALUE between(MarkdownTokenTypes.TEXT, MarkdownTokenTypes.TEXT) - .spacing(1, spaces, 0, markdown.KEEP_LINE_BREAKS_INSIDE_TEXT_BLOCKS && !markdown.WRAP_TEXT_IF_LONG, 0) + .spacing(1, spaces, 0, markdown.KEEP_LINE_BREAKS_INSIDE_TEXT_BLOCKS, 0) between(MarkdownTokenTypes.TEXT, MarkdownElementTypes.STRONG).spacing(1, spaces, 0, false, 0) between(MarkdownTokenTypes.TEXT, MarkdownElementTypes.EMPH).spacing(1, spaces, 0, false, 0) between(MarkdownTokenTypes.TEXT, MarkdownElementTypes.STRIKETHROUGH).spacing(1, spaces, 0, false, 0) diff --git a/plugins/markdown/test/data/formatter/keep_line_breaks_inside_text_block_after.md b/plugins/markdown/test/data/formatter/keep_line_breaks_inside_text_block_after.md new file mode 100644 index 000000000000..488daabca6c8 --- /dev/null +++ b/plugins/markdown/test/data/formatter/keep_line_breaks_inside_text_block_after.md @@ -0,0 +1,2 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur non dignissim tellus, sed feugiat ante. +In bibendum orci quis ultricies lobortis. Curabitur ac sapien efficitur quam ullamcorper varius. \ No newline at end of file diff --git a/plugins/markdown/test/data/formatter/keep_line_breaks_inside_text_block_before.md b/plugins/markdown/test/data/formatter/keep_line_breaks_inside_text_block_before.md new file mode 100644 index 000000000000..488daabca6c8 --- /dev/null +++ b/plugins/markdown/test/data/formatter/keep_line_breaks_inside_text_block_before.md @@ -0,0 +1,2 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur non dignissim tellus, sed feugiat ante. +In bibendum orci quis ultricies lobortis. Curabitur ac sapien efficitur quam ullamcorper varius. \ No newline at end of file diff --git a/plugins/markdown/test/data/formatter/reflow_no_extra_new_lines_keep_line_breaks_margin_80_before.md b/plugins/markdown/test/data/formatter/reflow_no_extra_new_lines_keep_line_breaks_margin_80_before.md deleted file mode 100644 index b21438600b27..000000000000 --- a/plugins/markdown/test/data/formatter/reflow_no_extra_new_lines_keep_line_breaks_margin_80_before.md +++ /dev/null @@ -1,3 +0,0 @@ -- **Logic:** Iterate through slides. For each slide, identify the Title shape and the content shapes - (Body). Process paragraphs within these shapes to maintain the hierarchical structure - (indentation). \ No newline at end of file diff --git a/plugins/markdown/test/data/formatter/reflow_no_extra_new_lines_keep_line_breaks_margin_80_after.md b/plugins/markdown/test/data/formatter/text_block_reflow_after_decreasing_margin_after.md similarity index 100% rename from plugins/markdown/test/data/formatter/reflow_no_extra_new_lines_keep_line_breaks_margin_80_after.md rename to plugins/markdown/test/data/formatter/text_block_reflow_after_decreasing_margin_after.md diff --git a/plugins/markdown/test/data/formatter/text_block_reflow_after_decreasing_margin_before.md b/plugins/markdown/test/data/formatter/text_block_reflow_after_decreasing_margin_before.md new file mode 100644 index 000000000000..7fc8b1840fcc --- /dev/null +++ b/plugins/markdown/test/data/formatter/text_block_reflow_after_decreasing_margin_before.md @@ -0,0 +1 @@ +- **Logic:** Iterate through slides. For each slide, identify the Title shape and the content shapes (Body). Process paragraphs within these shapes to maintain the hierarchical structure (indentation). \ No newline at end of file diff --git a/plugins/markdown/test/src/org/intellij/plugins/markdown/formatter/MarkdownFormatterTest.kt b/plugins/markdown/test/src/org/intellij/plugins/markdown/formatter/MarkdownFormatterTest.kt index e5be06164dc9..62989deb5fce 100644 --- a/plugins/markdown/test/src/org/intellij/plugins/markdown/formatter/MarkdownFormatterTest.kt +++ b/plugins/markdown/test/src/org/intellij/plugins/markdown/formatter/MarkdownFormatterTest.kt @@ -59,11 +59,37 @@ class MarkdownFormatterTest: LightPlatformCodeInsightTestCase() { fun `test reflow no extra new lines`() = doTest(rightMargin = 80) - fun `test reflow no extra new lines keep line breaks margin 80`() = doTest(rightMargin = 80, keepLineBreaks = true) + fun `test reflow no extra new lines keep line breaks margin 60`() = doTest(rightMargin = 60) - fun `test reflow no extra new lines keep line breaks margin 60`() = doTest(rightMargin = 60, keepLineBreaks = true) + fun `test reflow no extra new lines keep line breaks margin 40`() = doTest(rightMargin = 40) - fun `test reflow no extra new lines keep line breaks margin 40`() = doTest(rightMargin = 40, keepLineBreaks = true) + fun `test keep line breaks inside text block`() = doTest(rightMargin = 120, keepLineBreaks = true) + + // IJPL-241496: a single long line wrapped at 100 and then reformatted at 80 must reflow cleanly, + // not accumulate extra line breaks, when "keep line breaks inside text blocks" is disabled. + fun `test text block reflow after decreasing margin`() { + runWithTemporaryStyleSettings(project) { settings -> + settings.apply { + WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = true + getCustomSettings(MarkdownCustomCodeStyleSettings::class.java).apply { + FORMAT_TABLES = false + WRAP_TEXT_IF_LONG = true + KEEP_LINE_BREAKS_INSIDE_TEXT_BLOCKS = false + } + } + val common = settings.getCommonSettings(MarkdownLanguage.INSTANCE) + val after = getTestName(true) + "_after.md" + configureByFile(getTestName(true) + "_before.md") + common.RIGHT_MARGIN = 100 + performReformatting(project, file) + common.RIGHT_MARGIN = 80 + performReformatting(project, file) + checkResultByFile(after) + // reformatting again at 80 must stay stable + performReformatting(project, file) + checkResultByFile(after) + } + } fun `test emphasis`() = doTest()