From c109773d2adfa5340fc6ccc5a3239f7757b9eb79 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 23 Nov 2026 09:15:36 +0800 Subject: [PATCH] fix(editor): keep completion controls on one row (#5278) The completion footer keeps its shortcut hint and sorting control on one line. In narrow editor splits the hint shortens first, and hovering reveals its full text. The compact footer takes up less vertical space in the editor. --- e2e/codeInsight.spec.ts | 32 ++++++++++++++++++++++++++++++++ src/editor/lsp/completion.ts | 1 + src/editor/lsp/theme.ts | 29 +++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/e2e/codeInsight.spec.ts b/e2e/codeInsight.spec.ts index f27f1c1f9d..c5f65fac47 100644 --- a/e2e/codeInsight.spec.ts +++ b/e2e/codeInsight.spec.ts @@ -111,6 +111,7 @@ test("completion lists the server's items and inserts the chosen one", async ({ }); await expect(editor.locator(".cm-content")).toHaveCSS("font-size", zoomedSize); await expect(method.locator(".cm-completionLabel")).toHaveCSS("font-size", zoomedSize); + 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. @@ -124,6 +125,37 @@ test("completion lists the server's items and inserts the chosen one", async ({ await expect(popup).toBeHidden(); await expect(editor.locator(".cm-activeLine")).toHaveText(/^\s*order\.toDto\(\)$/); expect((await ipcCalls(page, "lsp_completion")).length).toBeGreaterThan(0); + + await page.evaluate(async () => { + const path = "/src/platform/actions.ts"; + await (await import(/* @vite-ignore */ path)).executeAction("editor.splitRight"); + }); + const panes = page.locator("[data-pane-id]"); + await expect(panes).toHaveCount(2); + await page.setViewportSize({ width: 480, height: 760 }); + await panes.last().locator(".cm-content").focus(); + await page.keyboard.press("End"); + await page.keyboard.press("Enter"); + await page.keyboard.type("order."); + await page.keyboard.press("Control+Space"); + const footer = popup.locator(".cm-lsp-completion-footer"); + await expect + .poll(() => + footer.evaluate((el) => { + const tip = el.querySelector("span")!; + const sort = el.querySelector("button")!; + const a = tip.getBoundingClientRect(); + const b = sort.getBoundingClientRect(); + return { + oneRow: Math.abs(a.y + a.height / 2 - b.y - b.height / 2) <= 1, + hintClipped: tip.scrollWidth > tip.clientWidth, + sortFits: sort.scrollWidth <= sort.clientWidth + 1 && b.right <= el.getBoundingClientRect().right, + }; + }), + ) + .toEqual({ oneRow: true, hintClipped: true, sortFits: true }); + await expect(footer.getByTitle("Press ↵ to insert, ⇥ to replace")).toHaveCSS("font-size", "12px"); + await expect(footer.getByRole("button", { name: "Sort by name" })).toBeInViewport({ ratio: 1 }); }); test("long completion signatures fit the editor when the workbench is narrowed", async ({ workbench: page }) => { diff --git a/src/editor/lsp/completion.ts b/src/editor/lsp/completion.ts index 71e4bd2593..96be344fe1 100644 --- a/src/editor/lsp/completion.ts +++ b/src/editor/lsp/completion.ts @@ -1045,6 +1045,7 @@ const completionPopup = ViewPlugin.fromClass( footer.className = "cm-lsp-completion-footer"; const tip = document.createElement("span"); tip.textContent = tx("Press ↵ to insert, ⇥ to replace"); + tip.title = tip.textContent; footer.append(tip, sortToggle(this.view)); } // CodeMirror appends a fresh list when the candidates change. diff --git a/src/editor/lsp/theme.ts b/src/editor/lsp/theme.ts index 6391bd3c67..0152182480 100644 --- a/src/editor/lsp/theme.ts +++ b/src/editor/lsp/theme.ts @@ -212,22 +212,28 @@ export const lspTheme = EditorView.theme({ color: "var(--fg-muted)", }, ".cm-lsp-completion-footer, .cm-lsp-inplace-footer": { - display: "flex", flex: "none", - flexWrap: "wrap", alignItems: "center", - padding: "5px 12px", backgroundColor: "var(--bg-popup-inline, var(--bg-elev))", color: "var(--fg-subtle)", fontFamily: "var(--font-ui)", fontSize: "var(--fs-small)", - gap: "var(--space-1) var(--space-3)", - justifyContent: "space-between", borderRadius: "0 0 calc(var(--radius-popup) - 1px) calc(var(--radius-popup) - 1px)", }, + ".cm-lsp-completion-footer": { + display: "grid", + gridTemplateColumns: "minmax(0, 1fr) minmax(0, max-content)", + gap: "var(--space-2)", + paddingBlock: "var(--space-1) 3px", + paddingInline: "var(--space-3) var(--space-2)", + }, + ".cm-lsp-completion-footer > span, .cm-lsp-completion-sort": { + minWidth: "0", + overflow: "hidden", + textOverflow: "ellipsis", + whiteSpace: "nowrap", + }, ".cm-lsp-completion-sort": { - flex: "none", - maxWidth: "100%", padding: "0", border: "none", background: "none", @@ -490,7 +496,14 @@ export const lspTheme = EditorView.theme({ '.cm-lsp-inplace-suggestions button[aria-current="true"]': { backgroundColor: "var(--bg-list-selected, var(--bg-tree-selected, var(--bg-selected-strong)))", }, - ".cm-lsp-inplace-footer": { overflowWrap: "anywhere" }, + ".cm-lsp-inplace-footer": { + display: "flex", + flexWrap: "wrap", + padding: "5px 12px", + gap: "var(--space-1) var(--space-3)", + justifyContent: "space-between", + overflowWrap: "anywhere", + }, // --- floating lightbulb (intentions.ts) ----------------------------------- ".cm-lsp-bulb": {