1
0

Fix slash command regex (broken on iOS)

This commit is contained in:
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, CompletionContext,
CompletionResult, CompletionResult,
} from "@codemirror/autocomplete"; } from "@codemirror/autocomplete";
import { slashCommandRegexp } from "../types";
import { safeRun } from "../../common/util"; import { safeRun } from "../../common/util";
import { Editor } from "../editor"; import { Editor } from "../editor";
import { syntaxTree } from "@codemirror/language"; import { syntaxTree } from "@codemirror/language";
@ -24,6 +23,8 @@ export type SlashCommandHookT = {
slashCommand?: SlashCommandDef; slashCommand?: SlashCommandDef;
}; };
const slashCommandRegexp = /([^\w]|^)\/[\w\-]*/;
export class SlashCommandHook implements Hook<SlashCommandHookT> { export class SlashCommandHook implements Hook<SlashCommandHookT> {
slashCommands = new Map<string, AppSlashCommand>(); slashCommands = new Map<string, AppSlashCommand>();
private editor: Editor; private editor: Editor;
@ -60,6 +61,7 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
if (!prefix) { if (!prefix) {
return null; return null;
} }
console.log("Match", prefix);
let options: Completion[] = []; let options: Completion[] = [];
// No slash commands in comment blocks (queries and such) // No slash commands in comment blocks (queries and such)
@ -90,7 +92,7 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
} }
return { return {
// + 1 because of the '/' // + 1 because of the '/'
from: prefix.from + 1, from: prefix.from + prefix.text.indexOf("/") + 1,
options: options, options: options,
}; };
} }

View File

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