gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong size when text is long on macOS

BeBeBerr opened this issue · comments

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

  • I can reproduce this issue with a vanilla SwiftUI project.
  • I can reproduce this issue using the main branch of this package.
  • This bug hasn't been addressed in an existing GitHub issue.

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

  • MarkdownUI: main
  • OS: macOS 14
  • Xcode: 15

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

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()
    }
}

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

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.