silverbullet/plugs/editor/command.ts

20 lines
538 B
TypeScript
Raw Permalink Normal View History

import { system } from "@silverbulletmd/silverbullet/syscalls";
2024-07-30 23:33:33 +08:00
import type { CompleteEvent } from "../../plug-api/types.ts";
2022-09-06 20:36:06 +08:00
export async function commandComplete(completeEvent: CompleteEvent) {
2024-02-23 20:50:59 +08:00
const match = /\{\[([^\]\[]*)$/.exec(completeEvent.linePrefix);
if (!match) {
2022-09-06 20:36:06 +08:00
return null;
}
2022-10-14 21:11:33 +08:00
const allCommands = await system.listCommands();
2022-09-06 20:36:06 +08:00
return {
from: completeEvent.pos - match[1].length,
2022-09-06 20:36:06 +08:00
options: Object.keys(allCommands).map((commandName) => ({
label: commandName,
type: "command",
})),
};
}