mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-17 08:08:55 +00:00
fix(editor): keep the completion hint below the suggestion list (#3283)
CodeMirror rebuilds the completion list by removing the old <ul> and appending a new one, so the advertiser bar (insert/replace hint and Sort by name), which was only added when missing, ended up above the list after the first refresh. An existing bar is now moved back behind the list. Co-authored-by: zhzhsx <1379025+zhzhsx@users.noreply.github.com>
This commit is contained in:
@@ -73,6 +73,13 @@ test("completion lists the server's items and inserts the chosen one", async ({
|
||||
await expect(method.locator(".cm-lsp-type")).toHaveText("OrderDto");
|
||||
await page.keyboard.type("toD");
|
||||
await expect(popup.getByText("total", { exact: true })).toBeHidden();
|
||||
// Refreshing the results rebuilds the list; the hint bar must stay below it, not jump to the top.
|
||||
const footerBelowList = await popup.evaluate((t) => {
|
||||
const list = t.querySelector(":scope > ul")!;
|
||||
const footer = t.querySelector(":scope > .cm-lsp-completion-footer")!;
|
||||
return footer.getBoundingClientRect().top >= list.getBoundingClientRect().bottom - 1;
|
||||
});
|
||||
expect(footerBelowList).toBe(true);
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(popup).toBeHidden();
|
||||
await expect(editor.locator(".cm-activeLine")).toHaveText(/^\s*order\.toDto\(\)$/);
|
||||
|
||||
@@ -602,6 +602,45 @@ describe("explicit completion", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("completion footer", () => {
|
||||
let view: EditorView | null = null;
|
||||
afterEach(() => {
|
||||
view?.destroy();
|
||||
view = null;
|
||||
});
|
||||
|
||||
it("stays below the list after CodeMirror rebuilds the options", async () => {
|
||||
const source: CompletionSource = (ctx) => ({
|
||||
from: ctx.pos,
|
||||
options: [{ label: "println" }, { label: "print" }],
|
||||
});
|
||||
view = new EditorView({
|
||||
state: EditorState.create({
|
||||
doc: "pri",
|
||||
selection: { anchor: 3 },
|
||||
extensions: [completionExtension(), EditorState.languageData.of(() => [{ openideaCompletion: source }])],
|
||||
}),
|
||||
parent: document.body,
|
||||
});
|
||||
startCompletion(view);
|
||||
await vi.waitFor(() =>
|
||||
expect(document.querySelector(".cm-tooltip-autocomplete > .cm-lsp-completion-footer")).not.toBeNull(),
|
||||
);
|
||||
const tooltip = document.querySelector<HTMLElement>(".cm-tooltip-autocomplete")!;
|
||||
const footer = tooltip.querySelector<HTMLElement>(":scope > .cm-lsp-completion-footer")!;
|
||||
expect(footer.previousElementSibling?.tagName).toBe("UL");
|
||||
|
||||
// CodeMirror removes the <ul> and appends a fresh one when the results change.
|
||||
tooltip.querySelector(":scope > ul")!.remove();
|
||||
tooltip.appendChild(document.createElement("ul"));
|
||||
expect(footer.previousElementSibling).toBeNull();
|
||||
|
||||
view.dispatch({});
|
||||
await vi.waitFor(() => expect(footer.previousElementSibling?.tagName).toBe("UL"));
|
||||
expect(tooltip.querySelectorAll(":scope > .cm-lsp-completion-footer")).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("typeColumnText", () => {
|
||||
const edit = (new_text: string) => [{ range: { start: { line: 0, col: 0 }, end: { line: 0, col: 0 } }, new_text }];
|
||||
|
||||
|
||||
@@ -758,8 +758,15 @@ const completionFooter = ViewPlugin.fromClass(
|
||||
...scope.querySelectorAll<HTMLElement>(".cm-tooltip-autocomplete"),
|
||||
];
|
||||
for (const t of tooltips) {
|
||||
if (t.querySelector(":scope > .cm-lsp-completion-footer")) continue;
|
||||
const footer = document.createElement("div");
|
||||
let footer = t.querySelector<HTMLElement>(":scope > .cm-lsp-completion-footer");
|
||||
if (footer) {
|
||||
// CodeMirror rebuilds the option list by appending a fresh <ul>,
|
||||
// which would leave an existing footer above the list.
|
||||
const list = t.querySelector(":scope > ul");
|
||||
if (list && list.nextElementSibling !== footer) list.after(footer);
|
||||
continue;
|
||||
}
|
||||
footer = document.createElement("div");
|
||||
footer.className = "cm-lsp-completion-footer";
|
||||
const tip = document.createElement("span");
|
||||
tip.textContent = tx("Press ↵ to insert, ⇥ to replace");
|
||||
|
||||
Reference in New Issue
Block a user