this repo has no description

commands: properly reimplement anyScopeRegex and automigrate calls that dont use it

Changed files
+26 -3
packages
core-extensions
src
commands
webpackModules
types
src
coreExtensions
+16
packages/core-extensions/src/commands/webpackModules/commands.ts
···
},
registerLegacyCommand(id, command) {
+
if (command.match) {
+
if (command.match instanceof RegExp) {
+
command.match = this.anyScopeRegex(command.match);
+
} else if (command.match.regex && typeof command.match !== "function") {
+
command.match = this.anyScopeRegex(command.match.regex);
+
}
+
}
+
if (!legacyCommands) {
queuedLegacyCommands![id] = command;
} else {
legacyCommands[id] = command;
}
+
},
+
+
anyScopeRegex(regex) {
+
const out = function (str: string) {
+
return regex.exec(str);
+
};
+
out.regex = regex;
+
return out;
},
_getCommands() {
+10 -3
packages/types/src/coreExtensions/commands.ts
···
}
);
+
export type AnyScopeRegex = RegExp["exec"] & {
+
regex: RegExp;
+
};
+
export type Commands = {
/**
* Register a command in the internal slash command system
···
registerLegacyCommand: (id: string, command: LegacyCommand) => void;
/**
+
* Creates a regular expression that legacy commands can understand
+
*/
+
anyScopeRegex: (regex: RegExp) => AnyScopeRegex;
+
+
/**
* @private
*/
_getCommands: () => RegisteredCommand[];
···
};
export type LegacyCommand = {
-
match?: {
-
regex: RegExp;
-
};
+
match?: RegExp | { regex: RegExp } | AnyScopeRegex;
action: (content: string, context: LegacyContext) => LegacyReturn;
};