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(grid): sync highlight scrollbar compensation and wrap alignment

lxk955145003646c4e
diff --git a/apps/desktop/src/components/grid/DataGridConditionEditor.vue b/apps/desktop/src/components/grid/DataGridConditionEditor.vue
index 25f2102c6a..ef6c68cecc 100644
--- a/apps/desktop/src/components/grid/DataGridConditionEditor.vue
+++ b/apps/desktop/src/components/grid/DataGridConditionEditor.vue
@@ -122,6 +122,7 @@ function onEditorScroll(event: Event) {
if (target === overlayRef.value) {
expandedHighlightScrollLeft.value = target.scrollLeft;
expandedHighlightScrollTop.value = target.scrollTop;
+ syncExpandedHighlightScrollbar();
} else {
collapsedHighlightScrollLeft.value = target.scrollLeft;
}
@@ -182,7 +183,8 @@ function measureExpandedHeight(input: HTMLTextAreaElement, rect: typeof expanded
const contentHeight = probe.scrollHeight;
probe.remove();
const availableHeight = Math.max(56, window.innerHeight - input.getBoundingClientRect().top - 12);
- return Math.min(Math.max(56, lineHeight * 2.5, contentHeight), Math.min(260, availableHeight));
+ const verticalInsets = Math.ceil(rect.inputTop) + 4;
+ return Math.min(Math.max(56, lineHeight * 2.5, contentHeight + verticalInsets), Math.min(260, availableHeight));
}
function maxExpandedHeight() {
@@ -196,10 +198,16 @@ function fitExpandedHeightToOverlay() {
if (!overlay) return;
const overflow = overlay.scrollHeight - overlay.clientHeight;
if (overflow > 4) {
- expandedHeight.value = Math.min(maxExpandedHeight(), expandedHeight.value + overflow);
+ const nextHeight = Math.min(maxExpandedHeight(), expandedHeight.value + overflow);
+ if (nextHeight !== expandedHeight.value) {
+ expandedHeight.value = nextHeight;
+ void nextTick(syncExpandedHighlightScrollbar);
+ return;
+ }
} else if (overflow <= 0) {
overlay.scrollTop = 0;
}
+ syncExpandedHighlightScrollbar();
}
function syncExpandedHighlightScrollbar() {
@@ -210,11 +218,7 @@ function syncExpandedHighlightScrollbar() {
}
function syncExpandedLayout() {
- syncExpandedHighlightScrollbar();
- // Re-fit once the compensation has been applied: the highlight layer now
- // wraps exactly like the textarea, so the pane can size itself to the real
- // content height instead of leaving a scrollbar that only the textarea sees.
- void nextTick(fitExpandedHeightToOverlay);
+ fitExpandedHeightToOverlay();
}
function measureExpandedRect(input: HTMLTextAreaElement) {
@@ -274,11 +278,14 @@ function resizeEditor(forceExpand = false) {
if (!wasExpanded) {
expandedHighlightScrollLeft.value = 0;
expandedHighlightScrollTop.value = 0;
+ expandedHighlightScrollbarWidth.value = 0;
}
const nextRect = measureExpandedRect(input);
expandedRect.value = nextRect;
expandedHeight.value = measureExpandedHeight(input, nextRect);
void nextTick(syncExpandedLayout);
+ } else {
+ expandedHighlightScrollbarWidth.value = 0;
}
expanded.value = nextExpanded;
updateSuggestionPosition();
@@ -431,6 +438,7 @@ function scheduleCollapse() {
editorFocused.value = false;
editor.dismiss();
expanded.value = false;
+ expandedHighlightScrollbarWidth.value = 0;
}, 0);
}
@@ -491,6 +499,7 @@ async function clearCondition() {
modelValue.value = "";
editor.dismiss();
expanded.value = false;
+ expandedHighlightScrollbarWidth.value = 0;
if (props.clear) await props.clear();
else emit("clear");
}
@@ -913,7 +922,6 @@ defineExpose({ focus, dismiss: editor.dismiss, rememberHistory: editor.rememberH
.data-grid-topbar-condition-input--expanded {
top: var(--data-grid-condition-input-top);
- right: 0.5rem;
bottom: 0.125rem;
left: 0.5rem;
height: auto;
diff --git a/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts
index 0345aca7ea..6d5964f15c 100644
--- a/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts
+++ b/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts
@@ -542,6 +542,68 @@ describe("DataGridConditionEditor quote completion", () => {
await nextTick();
expect(expandedHighlight?.style.getPropertyValue("--data-grid-condition-highlight-scrollbar")).toBe("10px");
+
+ // When the overlay fits without a scrollbar, the compensation resets to 0px
+ Object.defineProperties(overlay as HTMLTextAreaElement, {
+ offsetWidth: { configurable: true, value: 168 },
+ clientWidth: { configurable: true, value: 168 },
+ });
+ overlay?.dispatchEvent(new Event("input", { bubbles: true }));
+
+ await nextTick();
+ await nextTick();
+ await nextTick();
+
+ expect(expandedHighlight?.style.getPropertyValue("--data-grid-condition-highlight-scrollbar")).toBe("0px");
+ vi.unstubAllGlobals();
+ });
+
+ it("resets scrollbar compensation after fitExpandedHeightToOverlay eliminates overflow", async () => {
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {
+ const textWidth = (this.textContent?.length ?? 0) * 8;
+ const width = this.classList.contains("data-grid-topbar-condition-pane--expanded") ? 160 : textWidth;
+ return { x: 0, y: 0, left: 0, top: 0, right: width, bottom: 24, width, height: 24, toJSON: () => ({}) } as DOMRect;
+ });
+ vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(null);
+ vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => {
+ callback(0);
+ return 1;
+ });
+ const { input } = mountEditor("where", "test_item_id=12 and test_item_name=''");
+ mockTextareaMetrics(input, { clientWidth: 80, scrollWidth: 320 });
+ input.focus();
+ input.setSelectionRange(input.value.length, input.value.length);
+ input.dispatchEvent(new Event("focus", { bubbles: true }));
+
+ await nextTick();
+ await nextTick();
+
+ const overlay = document.body.querySelector(".data-grid-topbar-condition-input--expanded") as HTMLTextAreaElement | null;
+ const expandedHighlight = document.body.querySelector(".data-grid-condition-highlight--expanded") as HTMLElement | null;
+ expect(overlay).toBeTruthy();
+ expect(expandedHighlight).toBeTruthy();
+
+ let clientW = 160;
+ Object.defineProperties(overlay as HTMLTextAreaElement, {
+ offsetWidth: { configurable: true, value: 177 },
+ clientWidth: { configurable: true, get: () => clientW },
+ scrollHeight: { configurable: true, value: 80 },
+ clientHeight: { configurable: true, value: 56 },
+ });
+
+ overlay?.dispatchEvent(new Event("input", { bubbles: true }));
+ await nextTick();
+
+ // After fitExpandedHeightToOverlay increases height, the scrollbar disappears and clientWidth widens
+ clientW = 177;
+ Object.defineProperties(overlay as HTMLTextAreaElement, {
+ clientHeight: { configurable: true, value: 80 },
+ });
+
+ await nextTick();
+ await nextTick();
+
+ expect(expandedHighlight?.style.getPropertyValue("--data-grid-condition-highlight-scrollbar")).toBe("0px");
vi.unstubAllGlobals();
});
});