Fix slash command regex (broken on iOS)

pull/66/head
Zef Hemel 2022-08-02 13:22:10 +02:00
parent 9f7b59905a
commit 71211006cb
2 changed files with 4 additions and 4 deletions

View File

@ -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<SlashCommandHookT> {
slashCommands = new Map<string, AppSlashCommand>();
private editor: Editor;
@ -60,6 +61,7 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
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<SlashCommandHookT> {
}
return {
// + 1 because of the '/'
from: prefix.from + 1,
from: prefix.from + prefix.text.indexOf("/") + 1,
options: options,
};
}

View File

@ -1,8 +1,6 @@
import { AppCommand, CommandDef } from "./hooks/command";
import { FilterOption, PageMeta } from "@silverbulletmd/common/types";
export const slashCommandRegexp = /(?<!\w)\/[\w\-]*/;
export type Notification = {
id: number;
message: string;