1
0
silverbullet/plugs/editor/command.ts

20 lines
502 B
TypeScript
Raw Normal View History

2023-08-28 15:12:15 +00:00
import { system } from "$sb/syscalls.ts";
import { CompleteEvent } from "$sb/app_event.ts";
2022-09-06 12:36:06 +00:00
export async function commandComplete(completeEvent: CompleteEvent) {
const match = /\{\[([^\]]*)$/.exec(completeEvent.linePrefix);
if (!match) {
2022-09-06 12:36:06 +00:00
return null;
}
2022-10-14 13:11:33 +00:00
const allCommands = await system.listCommands();
2022-09-06 12:36:06 +00:00
return {
from: completeEvent.pos - match[1].length,
2022-09-06 12:36:06 +00:00
options: Object.keys(allCommands).map((commandName) => ({
label: commandName,
type: "command",
})),
};
}