swift-markdown-ui icon indicating copy to clipboard operation
swift-markdown-ui copied to clipboard

Can only select text from one paragraph at a time

Open everuribe opened this issue 2 years ago • 20 comments

Describe the bug When multiple paragraph strings are presented in a MarkdownUI view, the user can only select text from one paragraph at a time.

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 Explanation of how to reproduce the incorrect behavior. This could include an attached project, a link to code, or a Markdown-formatted text exhibiting the issue.

  1. Display multi-paragraph text broken up by newlines

Expected behavior Should be able to select across all paragraphs (except maybe if broken up by a different markdown section type)

Screenshots image

Version information

  • MarkdownUI: 2.2.0
  • OS: macOS Sonoma
  • Xcode: 15.0

everuribe avatar Oct 06 '23 21:10 everuribe

Hi @everuribe,

This is a known issue of MarkdownUI. The current implementation combines multiple Text and Image views into containing layout views, which makes text selection work only at a paragraph level. I don't have a solution at the moment, but I am trying different things to make text selection work.

gonzalezreal avatar Oct 09 '23 07:10 gonzalezreal

Thanks for the context! I guess it relies on newlines to be able to switch to a different markdown type and therefore view but maybe we can detect if it's just a continuation of the same markdown type and keep it in the same Text view? I assume this is already happening for code blocks.

everuribe avatar Oct 13 '23 14:10 everuribe

It's a bit more complicated than that. It doesn't rely on newlines, as spacing is configurable per block. On top of that, styling adds yet another layer of indirection. Regarding code blocks, those are rendered in a single view, so it works as you would expect.

As a workaround, you could add a gesture to the Markdown view that displays a context menu with an item to copy the contents.

gonzalezreal avatar Oct 13 '23 15:10 gonzalezreal

I found it's not working on Mac Catalyst

wyk111wyk avatar Mar 25 '24 11:03 wyk111wyk