Merge pull request #4763 from matrix-org/t3chguy/slash_cmd_ci

Fix case-sensitivity of /me to match rest of slash commands
This commit is contained in:
Michael Telatynski 2020-06-17 17:36:53 +01:00 committed by GitHub
commit 68ca8b3891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View file

@ -118,7 +118,7 @@ export class Command {
run(roomId: string, args: string, cmd: string) {
// if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me`
if (!this.runFn) return;
if (!this.runFn) return reject(_t("Command error"));
return this.runFn.bind(this)(roomId, args, cmd);
}

View file

@ -62,16 +62,20 @@ export function textSerialize(model: EditorModel) {
}
export function containsEmote(model: EditorModel) {
return startsWith(model, "/me ");
return startsWith(model, "/me ", false);
}
export function startsWith(model: EditorModel, prefix: string) {
export function startsWith(model: EditorModel, prefix: string, caseSensitive = true) {
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(prefix);
let text = firstPart && firstPart.text;
if (!caseSensitive) {
prefix = prefix.toLowerCase();
text = text.toLowerCase();
}
return firstPart && (firstPart.type === "plain" || firstPart.type === "command") && text.startsWith(prefix);
}
export function stripEmoteCommand(model: EditorModel) {

View file

@ -148,6 +148,7 @@
"Actions": "Actions",
"Advanced": "Advanced",
"Other": "Other",
"Command error": "Command error",
"Usage": "Usage",
"Prepends ¯\\_(ツ)_/¯ to a plain-text message": "Prepends ¯\\_(ツ)_/¯ to a plain-text message",
"Sends a message as plain text, without interpreting it as markdown": "Sends a message as plain text, without interpreting it as markdown",
@ -1170,7 +1171,6 @@
"All Rooms": "All Rooms",
"Search…": "Search…",
"Server error": "Server error",
"Command error": "Command error",
"Server unavailable, overloaded, or something else went wrong.": "Server unavailable, overloaded, or something else went wrong.",
"Unknown Command": "Unknown Command",
"Unrecognised command: %(commandText)s": "Unrecognised command: %(commandText)s",