support auto complete for /commands
This commit is contained in:
parent
88cc1c428d
commit
c5cd8b943a
4 changed files with 41 additions and 9 deletions
|
@ -303,7 +303,7 @@ export default class EditorModel {
|
|||
index = 0;
|
||||
}
|
||||
while (str) {
|
||||
const newPart = this._partCreator.createPartForInput(str);
|
||||
const newPart = this._partCreator.createPartForInput(str, index);
|
||||
if (validate) {
|
||||
str = newPart.appendUntilRejected(str);
|
||||
} else {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ export function mdSerialize(model) {
|
|||
case "newline":
|
||||
return html + "\n";
|
||||
case "plain":
|
||||
case "command":
|
||||
case "pill-candidate":
|
||||
case "at-room-pill":
|
||||
return html + part.text;
|
||||
|
@ -47,6 +48,7 @@ export function textSerialize(model) {
|
|||
case "newline":
|
||||
return text + "\n";
|
||||
case "plain":
|
||||
case "command":
|
||||
case "pill-candidate":
|
||||
case "at-room-pill":
|
||||
return text + part.text;
|
||||
|
@ -59,7 +61,11 @@ export function textSerialize(model) {
|
|||
|
||||
export function containsEmote(model) {
|
||||
const firstPart = model.parts[0];
|
||||
return firstPart && firstPart.type === "plain" && firstPart.text.startsWith("/me ");
|
||||
// part type will be "plain" while editing,
|
||||
// and "command" while composing a message.
|
||||
return firstPart &&
|
||||
(firstPart.type === "plain" || firstPart.type === "command") &&
|
||||
firstPart.text.startsWith("/me ");
|
||||
}
|
||||
|
||||
export function stripEmoteCommand(model) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue