amake / org_flutter

Org Mode widgets for Flutter
MIT License
17 stars 4 forks source link

Text can't be selected #7

Closed zikajk closed 1 year ago

zikajk commented 1 year ago

Hi! Is there any reason why the text can not be selected (SelectableText class)?

amake commented 1 year ago

In general you can select the text. Can you be more specific about what or where you're having trouble?

image

zikajk commented 1 year ago

That is interesting! I am testing the app in browser and simulator and I am not able to select anything. image

kresimir71 commented 1 year ago

I have the same experience with web pages created by Flutter. I've always assumed this is normal behavior because it's not HTML, it's a graphical output that doesn't use HTML.

zikajk commented 1 year ago

I have the same experience with web pages created by Flutter. I've always assumed this is normal behavior because it's not HTML, it's a graphical output that doesn't use HTML.

Once I use SelectableText class, then I can select the text (tested in one of buttons on the left side).

amake commented 1 year ago

Oops.

The screenshot I showed above was from Orgro, and while I remembered correctly that Flutter had changed something about how selection works such that SelectableText is not needed, I forgot the details of it.

In Orgro I wrap the relevant widget in SelectionArea. That seems to be sufficient to allow selection inside the Org document.

I did experiment with using SelectableText in org_flutter in the past, but

  1. I found there were differences in rendering, and I didn't want to try to figure out why
  2. Sometimes you don't want things to be selectable. For instance with the introduction of the OrgText widget, you can use Org markup to easily create a rich Text equivalent, which in the general case should not be selectable by default.
zikajk commented 1 year ago

Great, I didn't know about SelectionArea. It fullfills all my needs. Thank you for the info 🙏

amake commented 1 year ago

I've updated the readme to mention SelectionArea. I don't want to make any of org_flutter's widgets selectable by default per above, so I'll close this.

zikajk commented 1 year ago

@amake Can you select source-blocks in Orgro?
SelectionArea seems to have no effect.

And to add, really nice work, thank you for this!

amake commented 1 year ago

You can select source blocks but only if they don't have syntax highlighting applied (no language specified, or the language is not supported by flutter_highlight).

I haven't looked into why selection doesn't work with that package, but I do note that it seems abandoned and other, newer packages are available, so I am looking at moving to one of them.

amake commented 1 year ago

It looks like the reason is because flutter_highlight uses a new RichText widget: https://github.com/git-touch/highlight.dart/blob/8c08291d18d1e3fdab8564cc3f09726e262e555d/flutter_highlight/lib/flutter_highlight.dart#L93

Apparently you can make a RichText participate in the surrounding selection context relatively easily, but it requires a change to their library: https://api.flutter.dev/flutter/widgets/RichText-class.html#selections

amake commented 1 year ago

I have opened a fix for the issue with flutter_highlighting: https://github.com/akvelon/dart-highlighting/pull/71