support auto complete for /commands

This commit is contained in:
Bruno Windels 2019-08-21 15:27:50 +02:00
parent 88cc1c428d
commit c5cd8b943a
4 changed files with 41 additions and 9 deletions

View file

@ -441,3 +441,33 @@ export class PartCreator {
}
}
// part creator that support auto complete for /commands,
// used in SendMessageComposer
export class CommandPartCreator extends PartCreator {
createPartForInput(text, partIndex) {
// at beginning and starts with /? create
if (partIndex === 0 && text[0] === "/") {
return new CommandPart("", this._autoCompleteCreator);
} else {
return super.createPartForInput(text, partIndex);
}
}
deserializePart(part) {
if (part.type === "command") {
return new CommandPart(part.text, this._autoCompleteCreator);
} else {
return super.deserializePart(part);
}
}
}
class CommandPart extends PillCandidatePart {
acceptsInsertion(chr, i) {
return PlainPart.prototype.acceptsInsertion.call(this, chr, i);
}
get type() {
return "command";
}
}