Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow text selection #21

Closed
oatmealm opened this issue Jul 23, 2020 · 11 comments
Closed

Allow text selection #21

oatmealm opened this issue Jul 23, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@oatmealm
Copy link

It could be useful to make test selectable so we could search or look up using the native controls.

@amake
Copy link
Owner

amake commented Jul 23, 2020

I am building a complex tree of TextSpans including WidgetSpans to render the org document. If it's as simple as giving the tree to SelectableText.rich instead of Text.rich then this could be easy.

https://api.flutter.dev/flutter/material/SelectableText-class.html

@amake
Copy link
Owner

amake commented Jul 24, 2020

It's not quite trivial, but I was able to use SelectableText to make a lot of the text selectable.

However the result is quite underwhelming: Flutter does not use native controls, but rather reimplements workalikes. Currently it does not implement anything more than Select-All/Cut/Copy/Paste for text selection controls.

There is an open issue requesting more controls like Look Up:
flutter/flutter#24407

It's currently not possible to implement custom text selection controls in Flutter, but there is an issue for that, too:
flutter/flutter#31412

(If custom controls become possible then I could use this API to implement iOS dictionary lookup.)

Until there is movement on the above issues, I am going to say that supporting Look Up or similar is not feasible.

Do you still think it's worthwhile to have selectable (just copyable) text?

amake added a commit to amake/org_flutter that referenced this issue Jul 24, 2020
@oatmealm
Copy link
Author

oatmealm commented Jul 24, 2020

Ok, I understand. I didn't know Flutter reimplements all UI components, but being cross platform I guess I shouldn't be surprised.

About being able to select at all, yes, I think it's a fundamental thing in reference software to be able to copy and paste between apps...

@amake amake added the enhancement New feature or request label Jul 25, 2020
@amake
Copy link
Owner

amake commented Jul 30, 2020

Unfortunately I found that using SelectableText changes how text breaks lines. I was able to fix the one or two bad instances I noticed, but I'm worried that there's more I haven't found.

I'm going to hold off on selectability for now.

@chrstfer
Copy link

Any progress on this? As @oatmealm says it's pretty fundamental to plaintext apps/file formats that one can copy/cut/paste the text. Could you add a long-press option for a given (rendered) line/span that copies the contents to clipboard in org markdown format at least?

@amake
Copy link
Owner

amake commented Apr 28, 2021

I have not done any work on this since the last investigation.

Could you add a long-press option for a given (rendered) line/span that copies the contents to clipboard in org markdown format at least?

Off the top of my head there are several hurdles to that:

  • The AST does not retain its own original source, so the text you want to copy is not currently available at that layer
  • There is probably not a good way to make the tap target just "what you meant" and not significantly more or less: distinct runs of text are very granular at the AST level, so you'd end up copying a tiny bit (or a huge chunk) instead of just what you were aiming for
  • Long-press already has behavior for some elements (namely headlines); this new functionality would need to be reconciled with the old

@zy9306
Copy link

zy9306 commented Jan 14, 2022

If I just want to copy some text of the current line or some text of the current block, without any formatting issues, would it be easy to implement? I think there are very few scenarios where I need to copy, in my case, I sometimes need to copy a few words in an emergency.

@amake
Copy link
Owner

amake commented Jan 14, 2022

#21 (comment) is still unresolved; this blocks enabling selection at all.

When selection is enabled, I'm not sure how the built-in copying works and if it would be sufficient for your use case.

without any formatting issues

What do you mean by this?

@zy9306
Copy link

zy9306 commented Jan 15, 2022

@amake Sorry for my poor english. I seem to say something meaningless, please ignore.

In addition, if I compiled it into web page, can it work in the browser? I am not very familiar with flutter.

@amake
Copy link
Owner

amake commented Jan 15, 2022

In addition, if I compiled it into web page, can it work in the browser? I am not very familiar with flutter.

Orgro uses several plugins that don't support web, so unfortunately it can't target web right now.

amake added a commit to amake/org_flutter that referenced this issue Jan 15, 2022
amake added a commit to amake/org_flutter that referenced this issue Jan 16, 2022
@amake amake mentioned this issue Jul 4, 2022
@amake amake closed this as completed in accf4e2 Jul 5, 2022
@amake
Copy link
Owner

amake commented Jul 5, 2022

Flutter has introduced a new text selection mechanism that seems to work much better than the old one.

I have submitted beta versions for testing; look for v1.25.0.

amake added a commit that referenced this issue Oct 28, 2022
```
══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during a scheduler callback:
Layer OffsetEngineLayer was previously used as oldLayer.
Once a layer is used as oldLayer, it may not be used again. Instead, after calling one of the
SceneBuilder.push* methods and passing an oldLayer to it, use the layer returned by the method as
oldLayer in subsequent frames.
'dart:ui/compositing.dart':
Failed assertion: line 110 pos 9: '<optimized out>'

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack:
#2      _EngineLayerWrapper._debugCheckNotUsedAsOldLayer (dart:ui/compositing.dart:110:9)
#3      SceneBuilder.addRetained.<anonymous closure>.recursivelyCheckChildrenUsedOnce (dart:ui/compositing.dart:695:21)
#4      List.forEach (dart:core-patch/growable_array.dart:416:8)
#5      SceneBuilder.addRetained.<anonymous closure>.recursivelyCheckChildrenUsedOnce (dart:ui/compositing.dart:701:18)
#6      SceneBuilder.addRetained.<anonymous closure> (dart:ui/compositing.dart:704:7)
#7      SceneBuilder.addRetained (dart:ui/compositing.dart:707:6)
#8      Layer._addToSceneWithRetainedRendering (package:flutter/src/rendering/layer.dart:671:15)
#9      ContainerLayer.addChildrenToScene (package:flutter/src/rendering/layer.dart:1284:13)
#10     OffsetLayer.addToScene (package:flutter/src/rendering/layer.dart:1421:5)
#11     Layer._addToSceneWithRetainedRendering (package:flutter/src/rendering/layer.dart:674:5)
#12     ContainerLayer.addChildrenToScene (package:flutter/src/rendering/layer.dart:1284:13)
#13     ClipRectLayer.addToScene (package:flutter/src/rendering/layer.dart:1590:5)
#14     Layer._addToSceneWithRetainedRendering (package:flutter/src/rendering/layer.dart:674:5)
#15     ContainerLayer.addChildrenToScene (package:flutter/src/rendering/layer.dart:1284:13)
#16     OffsetLayer.addToScene (package:flutter/src/rendering/layer.dart:1421:5)
#17     Layer._addToSceneWithRetainedRendering (package:flutter/src/rendering/layer.dart:674:5)
#18     ContainerLayer.addChildrenToScene (package:flutter/src/rendering/layer.dart:1284:13)
#19     OffsetLayer.addToScene (package:flutter/src/rendering/layer.dart:1421:5)
#20     Layer._addToSceneWithRetainedRendering (package:flutter/src/rendering/layer.dart:674:5)
#21     ContainerLayer.addChildrenToScene (package:flutter/src/rendering/layer.dart:1284:13)
#22     OffsetLayer.addToScene (package:flutter/src/rendering/layer.dart:1421:5)
#23     Layer._addToSceneWithRetainedRendering (package:flutter/src/rendering/layer.dart:674:5)
#24     ContainerLayer.addChildrenToScene (package:flutter/src/rendering/layer.dart:1284:13)
#25     TransformLayer.addToScene (package:flutter/src/rendering/layer.dart:1914:5)
#26     ContainerLayer.buildScene (package:flutter/src/rendering/layer.dart:1097:5)
#27     RenderView.compositeFrame (package:flutter/src/rendering/view.dart:231:37)
#28     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:514:18)
#29     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:869:13)
#30     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:375:5)
#31     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1271:15)
#32     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1200:9)
#33     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1058:5)
#34     _invoke (dart:ui/hooks.dart:145:13)
#35     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:338:5)
#36     _drawFrame (dart:ui/hooks.dart:112:31)
(elided 2 frames from class _AssertionError)
════════════════════════════════════════════════════════════════════════════════════════════════════
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants