Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(editor): keep table hover open while typing in its search box

Loc Nguyen4586dcd44de5
diff --git a/apps/desktop/src/components/editor/queryEditorHoverContent.ts b/apps/desktop/src/components/editor/queryEditorHoverContent.ts
index 8341ca45b2..a5806502b3 100644
--- a/apps/desktop/src/components/editor/queryEditorHoverContent.ts
+++ b/apps/desktop/src/components/editor/queryEditorHoverContent.ts
@@ -127,6 +127,7 @@ export function createQueryEditorHoverContent(options: QueryEditorHoverContentOp
layoutController || handleCopy || searchController
? () => {
layoutController?.mount();
+ searchController?.pinTooltip(dom.closest<HTMLElement>(".cm-tooltip") ?? dom);
if (handleCopy) document.addEventListener("copy", handleCopy);
}
: undefined,
diff --git a/apps/desktop/src/lib/editor/__tests__/sqlHoverSearch.spec.ts b/apps/desktop/src/lib/editor/__tests__/sqlHoverSearch.spec.ts
index ccb82497b2..37cd29776e 100644
--- a/apps/desktop/src/lib/editor/__tests__/sqlHoverSearch.spec.ts
+++ b/apps/desktop/src/lib/editor/__tests__/sqlHoverSearch.spec.ts
@@ -517,4 +517,58 @@ describe("createHoverSearch", () => {
input.dispatchEvent(new Event("input"));
expect(target.firstChild).toBe(initialFirstChild);
});
+
+ describe("pinTooltip", () => {
+ function mountPinnedSearch() {
+ const host = document.createElement("div");
+ const target = document.createElement("div");
+ target.textContent = DDL;
+ const controller = createHoverSearch({ target, originalHtml: target.innerHTML, placeholder: "Search columns…", noResultLabel: "No matching columns" });
+ host.append(controller.element, target);
+ document.body.appendChild(host);
+ controller.pinTooltip(host);
+ const leave = vi.fn();
+ host.addEventListener("mouseleave", leave);
+ const input = controller.element.querySelector<HTMLInputElement>('[data-sql-hover-search-input="true"]')!;
+ return { controller, host, input, leave };
+ }
+
+ it("keeps the tooltip from seeing mouseleave while the search input is focused", () => {
+ const { host, input, leave } = mountPinnedSearch();
+ input.focus();
+ input.dispatchEvent(new CompositionEvent("compositionstart"));
+
+ host.dispatchEvent(new MouseEvent("mouseleave"));
+
+ expect(leave).not.toHaveBeenCalled();
+ });
+
+ it("lets mouseleave through when the search input is not focused", () => {
+ const { host, leave } = mountPinnedSearch();
+
+ host.dispatchEvent(new MouseEvent("mouseleave"));
+
+ expect(leave).toHaveBeenCalledTimes(1);
+ });
+
+ it("replays the missed mouseleave when the search input loses focus off the tooltip", () => {
+ const { host, input, leave } = mountPinnedSearch();
+ input.focus();
+ host.dispatchEvent(new MouseEvent("mouseleave"));
+
+ input.blur();
+
+ expect(leave).toHaveBeenCalledTimes(1);
+ });
+
+ it("stops pinning after destroy", () => {
+ const { controller, host, input, leave } = mountPinnedSearch();
+ input.focus();
+ controller.destroy();
+
+ host.dispatchEvent(new MouseEvent("mouseleave"));
+
+ expect(leave).toHaveBeenCalledTimes(1);
+ });
+ });
});
diff --git a/apps/desktop/src/lib/editor/sqlHoverSearch.ts b/apps/desktop/src/lib/editor/sqlHoverSearch.ts
index 54627888d5..b1cd8d7654 100644
--- a/apps/desktop/src/lib/editor/sqlHoverSearch.ts
+++ b/apps/desktop/src/lib/editor/sqlHoverSearch.ts
@@ -118,6 +118,12 @@ export interface HoverSearchController {
status: HTMLElement;
/** Focus the search input. */
focus(): void;
+ /**
+ * Keep the hover tooltip open while the search input has focus. CodeMirror
+ * closes hover tooltips on `mouseleave`, which Windows IME candidate windows
+ * trigger when they pop up over the pointer mid-composition.
+ */
+ pinTooltip(host: HTMLElement): void;
/** Remove listeners; safe to call once when the tooltip is destroyed. */
destroy(): void;
}
@@ -310,14 +316,32 @@ export function createHoverSearch(options: HoverSearchOptions): HoverSearchContr
input.addEventListener("pointerdown", stopPointer);
input.addEventListener("mousedown", stopPointer);
+ let pinnedHost: HTMLElement | null = null;
+ const keepPinnedTooltipOpen = (event: Event) => {
+ if (event.target === pinnedHost && document.activeElement === input) event.stopImmediatePropagation();
+ };
+ const releasePinnedTooltip = () => {
+ // Hand the leave CodeMirror missed back to it once typing is over.
+ if (pinnedHost && !pinnedHost.matches(":hover")) pinnedHost.dispatchEvent(new MouseEvent("mouseleave"));
+ };
+
return {
element,
status,
focus() {
input.focus();
},
+ pinTooltip(host) {
+ pinnedHost = host;
+ // Capture on the document runs before CodeMirror's listener on the host.
+ document.addEventListener("mouseleave", keepPinnedTooltipOpen, true);
+ input.addEventListener("blur", releasePinnedTooltip);
+ },
destroy() {
cancelPending();
+ document.removeEventListener("mouseleave", keepPinnedTooltipOpen, true);
+ input.removeEventListener("blur", releasePinnedTooltip);
+ pinnedHost = null;
input.removeEventListener("input", scheduleSearch);
input.removeEventListener("keydown", stopKeyboard);
input.removeEventListener("keyup", stopKeyboard);