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