allow inserting multiple parts at a position

pull/21833/head
Bruno Windels 2019-08-20 12:36:05 +02:00
parent ce44c651d0
commit 10c218825b
2 changed files with 11 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -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);
}