Merge pull request #3468 from matrix-org/bwindels/cider-autocomplete-fixes

Fix: when using autocomplete, ensure command is not sent as text, and @room notifs gets needed suffix
This commit is contained in:
Bruno Windels 2019-09-23 13:57:07 +00:00 committed by GitHub
commit 4933b9b050
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 14 deletions

View file

@ -100,19 +100,21 @@ export default class AutocompleteWrapperModel {
_partForCompletion(completion) {
const {completionId} = completion;
const text = completion.completion;
const firstChr = completionId && completionId[0];
switch (firstChr) {
case "@": {
if (completionId === "@room") {
return [this._partCreator.atRoomPill(completionId)];
} else {
return this._partCreator.createMentionParts(this._partIndex, text, completionId);
}
}
case "#":
return [this._partCreator.roomPill(completionId)];
// used for emoji and command completion replacement
switch (completion.type) {
case "room":
return [this._partCreator.roomPill(completionId), this._partCreator.plain(completion.suffix)];
case "at-room":
return [this._partCreator.atRoomPill(completionId), this._partCreator.plain(completion.suffix)];
case "user":
// not using suffix here, because we also need to calculate
// the suffix when clicking a display name to insert a mention,
// which happens in createMentionParts
return this._partCreator.createMentionParts(this._partIndex, text, completionId);
case "command":
// command needs special handling for auto complete, but also renders as plain texts
return [this._partCreator.command(text)];
default:
// used for emoji and other plain text completion replacement
return [this._partCreator.plain(text)];
}
}

View file

@ -456,15 +456,20 @@ export class CommandPartCreator extends PartCreator {
createPartForInput(text, partIndex) {
// at beginning and starts with /? create
if (partIndex === 0 && text[0] === "/") {
return new CommandPart("", this._autoCompleteCreator);
// text will be inserted by model, so pass empty string
return this.command("");
} else {
return super.createPartForInput(text, partIndex);
}
}
command(text) {
return new CommandPart(text, this._autoCompleteCreator);
}
deserializePart(part) {
if (part.type === "command") {
return new CommandPart(part.text, this._autoCompleteCreator);
return this.command(part.text);
} else {
return super.deserializePart(part);
}