diff --git a/src/components/views/rooms/SendMessageComposer.js b/src/components/views/rooms/SendMessageComposer.js index 0e03d83467..b6d9c42707 100644 --- a/src/components/views/rooms/SendMessageComposer.js +++ b/src/components/views/rooms/SendMessageComposer.js @@ -290,11 +290,12 @@ export default class SendMessageComposer extends React.Component { const member = this.props.room.getMember(userId); const displayName = member ? member.rawDisplayName : userId; - const userPillPart = partCreator.userPill(displayName, userId); const caret = this._editorRef.getCaret(); const position = model.positionForOffset(caret.offset, caret.atNodeEnd); + const insertIndex = position.index + 1; + const parts = partCreator.createMentionParts(insertIndex, displayName, userId); model.transform(() => { - const addedLen = model.insert([userPillPart], position); + const addedLen = model.insert(parts, position); return model.positionForOffset(caret.offset + addedLen, true); }); // refocus on composer, as we just clicked "Mention" diff --git a/src/editor/autocomplete.js b/src/editor/autocomplete.js index fe6f3bfe1f..beb155f297 100644 --- a/src/editor/autocomplete.js +++ b/src/editor/autocomplete.js @@ -106,9 +106,7 @@ export default class AutocompleteWrapperModel { if (completionId === "@room") { return [this._partCreator.atRoomPill(completionId)]; } else { - const pill = this._partCreator.userPill(text, completionId); - const postfix = this._partCreator.plain(this._partIndex === 0 ? ": " : " "); - return [pill, postfix]; + return this._partCreator.createMentionParts(this._partIndex, text, completionId); } } case "#": diff --git a/src/editor/parts.js b/src/editor/parts.js index 9ca9205bcd..c10392bfd2 100644 --- a/src/editor/parts.js +++ b/src/editor/parts.js @@ -441,6 +441,12 @@ export class PartCreator { const member = this._room.getMember(userId); return new UserPillPart(userId, displayName, member); } + + createMentionParts(partIndex, displayName, userId) { + const pill = this.userPill(displayName, userId); + const postfix = this.plain(partIndex === 0 ? ": " : " "); + return [pill, postfix]; + } } // part creator that support auto complete for /commands,