proton
proton copied to clipboard
Ask framework if selected range is a list
Hi,
Is there a way to ask the framework, for example the ListTextProcessor if the selected range is a list?
This would be good if you have a control to toggle lists on/off.
Thanks for a great framework! Jonathan
thanks, Jonathan.
ListTextProcessor
does not provide a mechanism to see if the selected range is list. However, you can check for that via attributedString using either of the following approaches:
editor.attributedText.attribute(.listItem, at: location, effectiveRange: nil) != nil
The location is the index of character in editor that you wish to test - or in your case, range.location.
If you have non-continuous range, you may also use:
editor.attributedText.enumerateAttribute(.listItem, in: range, options: .longestEffectiveRangeNotRequired) { (_, listRange, _) in
// your code here
}
longestEffectiveRangeNotRequired
will give you ranges when any of the attributes change i..e font, color etc. If you omit that, you will get longest continuous range that has .listItem
attribute with the same value. In other words, if this range is equal to your original range, it tells that the entire range is a list range.
Thanks for the quick answer. The problem I'm having with that approach is when I do the following.
- Start with an empty EditorView.
- Insert a list.
- Tap return/enter to get a second list line.
When doing this the didChangeSelectionAt delegate call returns a range that is (2, 0).
At the same time, the editor.attributedText.string.count returns 2. So the range is out of bounds of the text. I think this might have to do with blankLineFiller.
I'm using 0.5 Semi release btw.
Edit: This can be reproduced with CommandsExampleViewController
@YoX89, please let me know if this issue is still relevant. If not, I'd go ahead and close this.