gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.44k stars 298 forks source link

Wrong size when text is long on macOS #282

Closed BeBeBerr closed 8 months ago

BeBeBerr commented 9 months ago

Describe the bug When text is long, the window is expanded with extra space and cannot be resized. However, if the text is short, everything is fine.

Checklist

Steps to reproduce When text is very long:

import SwiftUI
import MarkdownUI

struct ContentView: View {
    var body: some View {
        Markdown("1232313123123123131312323131231231231313123231312312312313131232313123123123131312323131231231").border(Color.pink)
    }
}

The layout becomes weird. The window is actually way longer than my screen and I couldn't capture the whole window.

Screenshot 2023-12-20 at 2 44 37 PM

However, if I delete some text, everything is fine and I can resize the window with no issue.

Screenshot 2023-12-20 at 2 45 00 PM

Version information

This issue is introduced in version 2.0.0. Version 1.1.1 has no such issue. Any help will be appreciated!

gonzalezreal commented 8 months ago

Hi @BeBeBerr,

What is happening is that the current theme is applying the fixedSize(horizontal: false, vertical: true) on the paragraph contents.

You can workaround this issue by overriding the current paragraph style. For instance:

struct ContentView: View {
    var body: some View {
        Markdown("1232313123123123131312323131231231231313123231312312312313131232313123123123131312323131231231")
          .markdownBlockStyle(\.paragraph) { configuration in
            configuration.label
              .relativeLineSpacing(.em(0.15))
              .markdownMargin(top: .zero, bottom: .em(1))
          }
          .border(Color.pink)
          .padding()
    }
}
BeBeBerr commented 8 months ago

Thanks for replying! Is this considered as a bug and is there any plans to fix it? @gonzalezreal

gonzalezreal commented 8 months ago

I am not sure this is a bug. It can be argued what is best as the default behaviour. There were multiple bugs in the past related to not applying the fixedSize(horizontal: false, vertical: true) modifier by default in the themes that come with MarkdownUI, like #251 or #219.