Closed emallay closed 1 year ago
@emallay,
Thanks for the great questions.
- Interacting with Selected Spans
I'll update the example app with some sample code on how to do this.
- Support for RtL Languages?
In my use of this library I have not yet needed RTL support — but I know I will in the future, and have been planning on adding support at some point.
The key parts of the code that I know will need to change to support it are the updatedSelectionWith
function in selection_updater.dart, and the mergedToSelectionRects
methods on Iterable<TextBox>
and Iterable<Rect>
in common.dart. And undoubtably there are other parts of the code that will need to change as well.
It's complicated by the fact that a selection can span multiple RenderParagraphs, each of which can have a different text direction — so the solution needs to support this as well.
Feel free to look into adding this functionality if you want. :)
Thanks in advance for the example – very much appreciated.
Regarding RtL, if I can come up with a sufficiently robust solution, I will create a PR (I am not sure if my skills in this area will be up to the task, but I'm always game to try! LOL).
Hi Ron – I'm following up on the example you mentioned. Have you had an opportunity to put something together yet? I don't see any commits relating to the example. Thanks in advance!
@emallay,
I finally had some spare time to update the example app. Let me know if that's what you were looking for. Note, a full implementation would need other functions to manipulate the underlying text spans -- something to clear properties on the selected spans before updating a property like color, and something to simplify the underlying text span tree so it doesn't continue to become more and more complex, etc..
Hi @ronjb – I just ran the new example app and did a quick trace through the code. The handler code you've added clarifies a lot for me and is hugely helpful. Thank you very much for taking the time to implement this. Best wishes over the holidays!
1. Interacting with Selected Spans
When a selection is active and the menu is displayed, what is the best approach to interact with the underlying Text / TextSpan objects? For example, if the 'Foo' menu action was intended to make the selected text bold how does the callback identify the spans that need to be affected?
In case it makes a difference, in my usecase every word in the text will always be its own TextSpan. Would you happen to have a simple example illustrating something like that?
2. Support for RtL Languages? I didn’t see anything in the readme regarding limitations in support for top-to-bottom / right-to-left languages (Japanese, for example) but when looking through the comments in the source code I noted in common.dart that the doc comments for both
extension SelectableExtOnListOfRect on List<Rect>
andextension SelectableExtOnIterableOfRect
that it assumes the rectangles are in ‘reading order’.I don’t understand the code well enough yet to know how these extensions are used within the package so I am unclear if this means the package itself is strictly limited to left-to-right or if this has a less significant overall impact.
If it does mean only left-to-right is supported by the package, is there something inherent to the package’s architecture that would make it difficult to add support for top-to-bottom / right-to-left or is this just something that you haven’t implemented yet since it isn’t needed for your own usecase? If the latter, what areas of the code would I need to address if I decided to try to tackle this myself? It isn’t critical for my usecase but would be extremely helpful to have. I’m just curious what level of challenge would likely be involved if I were to try to refactor the code to support it.
Thanks in advance for any guidance on the above!