Merge pull request #5830 from SimonBrandner/fix-trailing-colon
Fix inserting trailing colon after mention/pill
This commit is contained in:
commit
14f1388522
3 changed files with 6 additions and 9 deletions
|
@ -506,9 +506,8 @@ export default class SendMessageComposer extends React.Component {
|
||||||
member.rawDisplayName : userId;
|
member.rawDisplayName : 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);
|
||||||
// index is -1 if there are no parts but we only care for if this would be the part in position 0
|
// Insert suffix only if the caret is at the start of the composer
|
||||||
const insertIndex = position.index > 0 ? position.index : 0;
|
const parts = partCreator.createMentionParts(caret.offset === 0, displayName, userId);
|
||||||
const parts = partCreator.createMentionParts(insertIndex, displayName, userId);
|
|
||||||
model.transform(() => {
|
model.transform(() => {
|
||||||
const addedLen = model.insert(parts, position);
|
const addedLen = model.insert(parts, position);
|
||||||
return model.positionForOffset(caret.offset + addedLen, true);
|
return model.positionForOffset(caret.offset + addedLen, true);
|
||||||
|
|
|
@ -125,10 +125,8 @@ export default class AutocompleteWrapperModel {
|
||||||
case "at-room":
|
case "at-room":
|
||||||
return [this.partCreator.atRoomPill(completionId), this.partCreator.plain(completion.suffix)];
|
return [this.partCreator.atRoomPill(completionId), this.partCreator.plain(completion.suffix)];
|
||||||
case "user":
|
case "user":
|
||||||
// not using suffix here, because we also need to calculate
|
// Insert suffix only if the pill is the part with index 0 - we are at the start of the composer
|
||||||
// the suffix when clicking a display name to insert a mention,
|
return this.partCreator.createMentionParts(this.partIndex === 0, text, completionId);
|
||||||
// which happens in createMentionParts
|
|
||||||
return this.partCreator.createMentionParts(this.partIndex, text, completionId);
|
|
||||||
case "command":
|
case "command":
|
||||||
// command needs special handling for auto complete, but also renders as plain texts
|
// command needs special handling for auto complete, but also renders as plain texts
|
||||||
return [(this.partCreator as CommandPartCreator).command(text)];
|
return [(this.partCreator as CommandPartCreator).command(text)];
|
||||||
|
|
|
@ -535,9 +535,9 @@ export class PartCreator {
|
||||||
return new UserPillPart(userId, displayName, member);
|
return new UserPillPart(userId, displayName, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
createMentionParts(partIndex: number, displayName: string, userId: string) {
|
createMentionParts(insertTrailingCharacter: boolean, displayName: string, userId: string) {
|
||||||
const pill = this.userPill(displayName, userId);
|
const pill = this.userPill(displayName, userId);
|
||||||
const postfix = this.plain(partIndex === 0 ? ": " : " ");
|
const postfix = this.plain(insertTrailingCharacter ? ": " : " ");
|
||||||
return [pill, postfix];
|
return [pill, postfix];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue