Fix escaping commands using double-slash //, e.g //plain sends /plain

This commit is contained in:
Michael Telatynski 2020-01-21 15:55:21 +00:00
parent adec308529
commit b5e902e1f2
2 changed files with 17 additions and 4 deletions

View file

@ -61,18 +61,26 @@ export function textSerialize(model) {
}
export function containsEmote(model) {
return startsWith(model, "/me ");
}
export function startsWith(model, prefix) {
const firstPart = model.parts[0];
// 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 ");
firstPart.text.startsWith(prefix);
}
export function stripEmoteCommand(model) {
// trim "/me "
return stripPrefix(model, "/me ");
}
export function stripPrefix(model, prefix) {
model = model.clone();
model.removeText({index: 0, offset: 0}, 4);
model.removeText({index: 0, offset: 0}, prefix.length);
return model;
}