Skip to content

Commit 68ca8b3

Browse files
authored
Merge pull request matrix-org#4763 from matrix-org/t3chguy/slash_cmd_ci
Fix case-sensitivity of /me to match rest of slash commands
2 parents 58671f0 + ef80a0b commit 68ca8b3

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/SlashCommands.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class Command {
118118

119119
run(roomId: string, args: string, cmd: string) {
120120
// if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me`
121-
if (!this.runFn) return;
121+
if (!this.runFn) return reject(_t("Command error"));
122122
return this.runFn.bind(this)(roomId, args, cmd);
123123
}
124124

src/editor/serialize.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,20 @@ export function textSerialize(model: EditorModel) {
6262
}
6363

6464
export function containsEmote(model: EditorModel) {
65-
return startsWith(model, "/me ");
65+
return startsWith(model, "/me ", false);
6666
}
6767

68-
export function startsWith(model: EditorModel, prefix: string) {
68+
export function startsWith(model: EditorModel, prefix: string, caseSensitive = true) {
6969
const firstPart = model.parts[0];
7070
// part type will be "plain" while editing,
7171
// and "command" while composing a message.
72-
return firstPart &&
73-
(firstPart.type === "plain" || firstPart.type === "command") &&
74-
firstPart.text.startsWith(prefix);
72+
let text = firstPart && firstPart.text;
73+
if (!caseSensitive) {
74+
prefix = prefix.toLowerCase();
75+
text = text.toLowerCase();
76+
}
77+
78+
return firstPart && (firstPart.type === "plain" || firstPart.type === "command") && text.startsWith(prefix);
7579
}
7680

7781
export function stripEmoteCommand(model: EditorModel) {

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"Actions": "Actions",
149149
"Advanced": "Advanced",
150150
"Other": "Other",
151+
"Command error": "Command error",
151152
"Usage": "Usage",
152153
"Prepends ¯\\_(ツ)_/¯ to a plain-text message": "Prepends ¯\\_(ツ)_/¯ to a plain-text message",
153154
"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 @@
11701171
"All Rooms": "All Rooms",
11711172
"Search…": "Search…",
11721173
"Server error": "Server error",
1173-
"Command error": "Command error",
11741174
"Server unavailable, overloaded, or something else went wrong.": "Server unavailable, overloaded, or something else went wrong.",
11751175
"Unknown Command": "Unknown Command",
11761176
"Unrecognised command: %(commandText)s": "Unrecognised command: %(commandText)s",

0 commit comments

Comments
 (0)