Global anchor completion
This commit is contained in:
parent
74387cb5b1
commit
3f1aa45b5d
@ -1,7 +1,7 @@
|
||||
import { collectNodesOfType } from "$sb/lib/tree.ts";
|
||||
import type { CompleteEvent, IndexTreeEvent } from "$sb/app_event.ts";
|
||||
import { removeQueries } from "$sb/lib/query.ts";
|
||||
import { ObjectValue } from "$sb/types.ts";
|
||||
import { ObjectValue, QueryExpression } from "$sb/types.ts";
|
||||
import { indexObjects, queryObjects } from "./api.ts";
|
||||
|
||||
type AnchorObject = ObjectValue<{
|
||||
@ -34,17 +34,20 @@ export async function anchorComplete(completeEvent: CompleteEvent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let [pageRef, anchorRef] = match[1].split("@");
|
||||
const pageRef = match[1].split("@")[0];
|
||||
let filter: QueryExpression | undefined = ["=", ["attr", "page"], [
|
||||
"string",
|
||||
pageRef,
|
||||
]];
|
||||
if (!pageRef) {
|
||||
pageRef = completeEvent.pageName;
|
||||
// "bare" anchor, match any page for completion purposes
|
||||
filter = undefined;
|
||||
}
|
||||
const allAnchors = await queryObjects<AnchorObject>("anchor", {
|
||||
filter: ["=", ["attr", "page"], ["string", pageRef]],
|
||||
});
|
||||
const allAnchors = await queryObjects<AnchorObject>("anchor", { filter });
|
||||
return {
|
||||
from: completeEvent.pos - anchorRef.length,
|
||||
from: completeEvent.pos - match[1].length,
|
||||
options: allAnchors.map((a) => ({
|
||||
label: a.name,
|
||||
label: a.page === completeEvent.pageName ? `@${a.name}` : a.ref,
|
||||
type: "anchor",
|
||||
})),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user