-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Hi,
In our app we have three different list styles the user can choose between. Bullets •, Dashes -, or Numbers 1. We do this by putting a string in the attributeValue of the ListCommand, for example "NumberList". Then in our EditorListFormattingProvider in the EditorListFormattingProvider.listLineMarkerFor(editor:index:level:previousLevel:attributeValue:) method we parse the attributeValue as a string and return different ListLineMarkers depending on the string.
This is done as according to the documentation of attributeValue:
/// This may be used to store info that helps generate appropriate markers for e.g. storing context related
/// to bullet vs ordered lists.
Here's a small diff showing in the CommandsExampleViewController how we achieve that.
diff.log
The problem occurs when the user switches between the different styles.
Here's how to reproduce with the modified version of the CommandsExampleViewController
- Tap "List"
- Write any word and tap enter
- Tap "Bullet List"
- List Style disappears instead of changing to a bulleted list.
- Tap "Bullet List" again
- Both list styles are shown at the same time.
Here's a gif showing what happens:
For step number 4 the reason that happens is because of this code in ListCommand
guard selectedRange.length > 0 else {
if editor.isEmpty ||
editor.attributedText.attribute(.listItem, at: max(0, editor.selectedRange.location - 1), effectiveRange: nil) == nil {
ListTextProcessor().createListItemInANewLine(editor: editor, editedRange: selectedRange, indentMode: .indent, attributeValue: attributeValue)
} else {
ListTextProcessor().exitList(editor: editor)
}
return
}
Because we already have a non-nil attributeValue the code goes into the else and exitList(). I wonder if it would make sense to compare the attribute value in the attributedString to the one in the command to see if they are not the same, then change to the new one instead of exiting the list. One problem though is that Any? is not equatable, but there are ways to work around that.
For the duplicate list markers shown I think it has to do with the newline character between line 1 and 2 has a different style than the blank filler on line 2.