1
0
silverbullet/plugs/directive/complete.ts
Zef Hemel 3545d00d46
Major mini editor refactoring (#225)
Replaces most editing components with CM components, enabling vim mode and completions everywhere

Fixes #205 
Fixes #221 
Fixes #222 
Fixes #223
2022-12-21 14:55:24 +01:00

21 lines
574 B
TypeScript

import { events } from "$sb/plugos-syscall/mod.ts";
import { CompleteEvent } from "../../plug-api/app_event.ts";
export async function queryComplete(completeEvent: CompleteEvent) {
const match = /#query ([\w\-_]+)*$/.exec(completeEvent.linePrefix);
if (!match) {
return null;
}
const allEvents = await events.listEvents();
return {
from: completeEvent.pos - match[1].length,
options: allEvents
.filter((eventName) => eventName.startsWith("query:"))
.map((source) => ({
label: source.substring("query:".length),
})),
};
}