commands: properly reimplement anyScopeRegex and automigrate calls that dont use it
Cynthia Foxwell 1 month ago 2 files (+26, -3)
@@ -40,11 +40,27 @@ registeredCommands.push(registered);},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() {
@@ -94,6 +94,10 @@ value: string;});+export type AnyScopeRegex = RegExp["exec"] & {+ regex: RegExp;+};+export type Commands = {/*** Register a command in the internal slash command system@@ -106,6 +110,11 @@ */registerLegacyCommand: (id: string, command: LegacyCommand) => void;/**+ * Creates a regular expression that legacy commands can understand+ */+ anyScopeRegex: (regex: RegExp) => AnyScopeRegex;++ /*** @private*/_getCommands: () => RegisteredCommand[];@@ -121,8 +130,6 @@ content: string;};export type LegacyCommand = {- match?: {- regex: RegExp;- };+ match?: RegExp | { regex: RegExp } | AnyScopeRegex;action: (content: string, context: LegacyContext) => LegacyReturn;};