Gutenberg-mobile: Fix caret position after inline paste - is broken

Created on 20 Apr 2019  路  5Comments  路  Source: wordpress-mobile/gutenberg-mobile

As @mkevins reported :

After inline paste, the caret position should be "incremented" by the length of the inserted text. This is set explicitly during the paste handling via the forceSelectionUpdate method. A safety check was added to the render method to prevent an out of bounds exception that can occur when the caret is moved to a position that is larger than the text buffer, which may happen as a result of Aztec trimming spaces in the content.

For the purpose of checking this condition, the willTrimSpaces method https://github.com/WordPress/gutenberg/pull/15021/files#diff-4828a21853e899e5a36faecfa96d83e8R631 was introduced, which tries to evaluate whether Aztec will trim spaces, and if so, prevents setting the caret position. The regex that looks for outer spaces (that will be trimmed) also matches on any spaces adjacent to html tags (including inner tags). The result is that whenever the html contains inner tags adjacent to spaces (e.g. a bold word), the caret will not be in the correct position after paste.

[Type] Bug

All 5 comments

Hey, @hypest @mkevins I have opened the issue regarding regression that @mkevins has mentioned.

Sorry, it's not very clear to me what the issue is, so it's hard to prioritize. Can you edit the description in terms of what is broken and adding steps to reproduce and screenshot/gif/video (if it makes sense)?

Moving to next milestone.

After inline paste, the caret position should be "incremented" by the length of the inserted text. This is set explicitly during the paste handling via the forceSelectionUpdate method. A safety check was added to the render method to prevent an out of bounds exception that can occur when the caret is moved to a position that is larger than the text buffer, which may happen as a result of Aztec trimming spaces in the content.
For the purpose of checking this condition, the willTrimSpaces method was introduced, which tries to evaluate whether Aztec will trim spaces, and if so, prevents setting the caret position. The regex that looks for outer spaces (that will be trimmed) also matches on any spaces adjacent to html tags (including inner tags). The result is that whenever the html contains inner tags adjacent to spaces (e.g. a bold word), the caret will not be in the correct position after paste.

Hey @koke,
sorry for not being clear here, I have updated the description based on @mkevins explanation.

If something else needs to be changed, please let me know. Thanks.

Was this page helpful?
0 / 5 - 0 ratings