diff --git a/packages/web/hooks/slash_command.ts b/packages/web/hooks/slash_command.ts index 71a9e5a..b47c5f3 100644 --- a/packages/web/hooks/slash_command.ts +++ b/packages/web/hooks/slash_command.ts @@ -5,7 +5,6 @@ import { CompletionContext, CompletionResult, } from "@codemirror/autocomplete"; -import { slashCommandRegexp } from "../types"; import { safeRun } from "../../common/util"; import { Editor } from "../editor"; import { syntaxTree } from "@codemirror/language"; @@ -24,6 +23,8 @@ export type SlashCommandHookT = { slashCommand?: SlashCommandDef; }; +const slashCommandRegexp = /([^\w]|^)\/[\w\-]*/; + export class SlashCommandHook implements Hook { slashCommands = new Map(); private editor: Editor; @@ -60,6 +61,7 @@ export class SlashCommandHook implements Hook { if (!prefix) { return null; } + console.log("Match", prefix); let options: Completion[] = []; // No slash commands in comment blocks (queries and such) @@ -90,7 +92,7 @@ export class SlashCommandHook implements Hook { } return { // + 1 because of the '/' - from: prefix.from + 1, + from: prefix.from + prefix.text.indexOf("/") + 1, options: options, }; } diff --git a/packages/web/types.ts b/packages/web/types.ts index f9f70a2..68b2bf3 100644 --- a/packages/web/types.ts +++ b/packages/web/types.ts @@ -1,8 +1,6 @@ import { AppCommand, CommandDef } from "./hooks/command"; import { FilterOption, PageMeta } from "@silverbulletmd/common/types"; -export const slashCommandRegexp = /(?