1
0
silverbullet/plugs/tasks/complete.ts
Zef Hemel 0313565610
Complete redo of content indexing and querying (#517)
Complete redo of data store
Introduces live queries and live templates
2023-10-03 14:16:33 +02:00

22 lines
623 B
TypeScript

import { CompleteEvent } from "$sb/app_event.ts";
import { queryObjects } from "../index/plug_api.ts";
import { TaskStateObject } from "./task.ts";
export async function completeTaskState(completeEvent: CompleteEvent) {
const taskMatch = /([\-\*]\s+\[)([^\[\]]+)$/.exec(
completeEvent.linePrefix,
);
if (!taskMatch) {
return null;
}
const allStates = await queryObjects<TaskStateObject>("taskstate", {});
const states = [...new Set(allStates.map((s) => s.state))];
return {
from: completeEvent.pos - taskMatch[2].length,
options: states.map((state) => ({
label: state,
})),
};
}