diff --git a/src/components/views/rooms/SendMessageComposer.js b/src/components/views/rooms/SendMessageComposer.js index 916f93d544..b3c65b5a97 100644 --- a/src/components/views/rooms/SendMessageComposer.js +++ b/src/components/views/rooms/SendMessageComposer.js @@ -134,7 +134,7 @@ export default class SendMessageComposer extends React.Component { const displayName = member ? member.rawDisplayName : payload.user_id; const userPillPart = this.model.partCreator.userPill(displayName, userId); - this.model.insertPartAt(userPillPart, this._editorRef.getCaret()); + this.model.insertPartsAt([userPillPart], this._editorRef.getCaret()); break; } } diff --git a/src/editor/model.js b/src/editor/model.js index 3a8c02da1b..99d590bf26 100644 --- a/src/editor/model.js +++ b/src/editor/model.js @@ -108,12 +108,18 @@ export default class EditorModel { this._updateCallback(caret, inputType); } - insertPartAt(part, caret) { + insertPartsAt(parts, caret) { const position = this.positionForOffset(caret.offset, caret.atNodeEnd); const insertIndex = this._splitAt(position); - this._insertPart(insertIndex, part); - // want to put caret after new part? - const newPosition = new DocumentPosition(insertIndex, part.text.length); + let newTextLength = 0; + for (let i = 0; i < parts.length; ++i) { + const part = parts[i]; + newTextLength += part.text.length; + this._insertPart(insertIndex + i, part); + } + // put caret after new part + const lastPartIndex = insertIndex + parts.length - 1; + const newPosition = new DocumentPosition(lastPartIndex, newTextLength); this._updateCallback(newPosition); }