- Create a document with two paragraphs, and make both of them entirely bold
- Put the cursor at the beginning of the first paragraph, and type a character. This character will be bold
- Put the cursor at the beginning of the second paragraph, and type a character. This character will not be bold
#2 and #3 should be consistent. In fact, #2 *only* happens at the very start of the document, #3 happens everywhere else.
The reason this is broken is that the code computing the new insertionAnnotations in ve.dm.Surface#setSelection by pulling from the left does not take paragraph boundaries into account at all. In case #3, it tries to pull from the left across the paragraph boundary, but because getAnnotationsFromOffset() doesn't work the way it thinks it does (the offset at the end of the first paragraph is a content offset, but getting its annotations returns an empty set) that doesn't work, and so text inserted at the beginning of this paragraph is not annotated. However, at the very start, the getRelativeContentOffset() call that computes the offset to the left bounces back and returns the offset to the right instead (1), so left === right, and we end up pulling from the right and bolding the inserted text.
So really, the code is trying to achieve the wrong behavior (#2), but in most cases that breaks and we end up with the right behavior (#3). So the correct behavior is achieved completely by accident, except in one edge case where the code successfully achieves the wrong behavior.
Version: unspecified
Severity: normal