mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
Indexed markers (Edges.markers) were always drawn with the navigation glyph, so a plugin couldn't tell its marker kinds apart. A [[contributes.markerIcons]] entry can now claim them by key prefix (`markers`), with an optional `tooltip` shown above the targets. The host matches the longest prefix and sends the declaration id with each marker; the editor resolves the icon and the translated tooltip from the projected declaration. Manifest only, under the existing API 1.3 gate of markerIcons. Closes #2194
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { tx } from "@/platform/i18n";
|
|
import { navigateTo, locationItems } from "@/editor/lsp/navigation";
|
|
import { openPopup } from "@/editor/lsp/popupStore";
|
|
import { gutterIconMarkup, isIconName } from "@/ui/icons";
|
|
import type { Location } from "@/platform/ipc";
|
|
|
|
async function openTargets(targets: Location[], element: HTMLElement) {
|
|
if (targets.length === 1) {
|
|
await navigateTo(targets[0]!);
|
|
return;
|
|
}
|
|
const rect = element.getBoundingClientRect();
|
|
openPopup({
|
|
kind: "list",
|
|
title: tx`Choose Mapping Target`,
|
|
anchor: { x: rect.left, y: rect.bottom + 2 },
|
|
items: await locationItems(targets),
|
|
});
|
|
}
|
|
/** Shared ordinary-click and keyboard navigation for interactive and indexed markers. */
|
|
export function navigationButton(targets: Location[], icon: string, tooltip?: string | null): HTMLButtonElement {
|
|
const button = document.createElement("button");
|
|
button.type = "button";
|
|
button.className = "cm-plugin-mapping-button";
|
|
const places = targets.map((t) => `${t.path.split("/").pop()}:${t.range.start.line + 1}`);
|
|
button.title = (tooltip ? [tooltip, ...places] : places).join("\n");
|
|
button.setAttribute("aria-label", tx`Go to mapping: ${button.title}`);
|
|
button.innerHTML = gutterIconMarkup(isIconName(icon) ? icon : "arrow-right") ?? "";
|
|
button.onclick = (event) => {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
void openTargets(targets, button);
|
|
};
|
|
return button;
|
|
}
|