And remedy weird API in the process. Autocomplete now exposes `onSelectionChange` to indicate that the user has selected another completion, rather than returning the chosen completion via onUpArrow etc.
Fixesvector-im/riot-web#4835
because using `body` gives inconsistent results - sometimes it will contain markdown and sometimes not, and this may not correspond with the `formatted_body`.
TODO: Do quoting proper - using `in_response_to`.
(not formatted_body)
This is because draft-js has regressed with a bug that causes some entities to not exist within a given ContentState - see vector-im/riot-web#4756
This makes sure that the length of the range for a completed Entity = the length of the text in the decoration, which apparently draftjs assumes when calculating selection state offsets.
Fixes https://github.com/vector-im/riot-web/issues/4666
Tab-completing a room alias inserts a markdown link, which is now stripped before a command is parsed. We also strip the MD links when doing the autocompletion itself (getAutocompleteQuery).
There is still an issue where `/invite` will not work at all with tab-completion - the text of a user Pill is not the userID but rather the display name, which cannot be used as an argument to the command.
This makes sure the selection state is correct when moving the cursor through an entity in the composer but only in rich text mode. https://github.com/vector-im/riot-web/issues/4666 still persists despite this, probably because the text content inserted during a completion in markdown mode has a different length to the text node within the entity.
fixesvector-im/riot-web#4654
Instead of blindly stripping all MD mentions, only strip those that were tab-completed. We do this by adding the `isCompleted` flag to the Entity data.
This isn't an entirely side-effect-free refactoring:
- the text of the timeline pills is now either the room ID/alias or user ID/ display name of the linked resource (which means that until we do a roundtrip to get user displaynames, mentions for users not in the current room will have their user IDs shown instead of what was in the link body).
- timeline links to rooms without avatars are now rendered as links
- fixed issue that would throw an error whilst rendering (i.e. unusable client) a room link to a room that the client doesn't know about