share user pill postfix between autocomplete and insert mention

where we decide to add a colon only if the composer is empty
This commit is contained in:
Bruno Windels 2019-09-02 14:06:30 +02:00
parent c219f925c6
commit c595371845
3 changed files with 10 additions and 5 deletions

View file

@ -290,11 +290,12 @@ export default class SendMessageComposer extends React.Component {
const member = this.props.room.getMember(userId); const member = this.props.room.getMember(userId);
const displayName = member ? const displayName = member ?
member.rawDisplayName : userId; member.rawDisplayName : userId;
const userPillPart = partCreator.userPill(displayName, userId);
const caret = this._editorRef.getCaret(); const caret = this._editorRef.getCaret();
const position = model.positionForOffset(caret.offset, caret.atNodeEnd); const position = model.positionForOffset(caret.offset, caret.atNodeEnd);
const insertIndex = position.index + 1;
const parts = partCreator.createMentionParts(insertIndex, displayName, userId);
model.transform(() => { model.transform(() => {
const addedLen = model.insert([userPillPart], position); const addedLen = model.insert(parts, position);
return model.positionForOffset(caret.offset + addedLen, true); return model.positionForOffset(caret.offset + addedLen, true);
}); });
// refocus on composer, as we just clicked "Mention" // refocus on composer, as we just clicked "Mention"

View file

@ -106,9 +106,7 @@ export default class AutocompleteWrapperModel {
if (completionId === "@room") { if (completionId === "@room") {
return [this._partCreator.atRoomPill(completionId)]; return [this._partCreator.atRoomPill(completionId)];
} else { } else {
const pill = this._partCreator.userPill(text, completionId); return this._partCreator.createMentionParts(this._partIndex, text, completionId);
const postfix = this._partCreator.plain(this._partIndex === 0 ? ": " : " ");
return [pill, postfix];
} }
} }
case "#": case "#":

View file

@ -441,6 +441,12 @@ export class PartCreator {
const member = this._room.getMember(userId); const member = this._room.getMember(userId);
return new UserPillPart(userId, displayName, member); 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, // part creator that support auto complete for /commands,