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(diff): sync horizontal scroll in schema comparison

jearhef12ac21453ec
diff --git a/apps/desktop/src/composables/__tests__/useDiffScrollSync.spec.ts b/apps/desktop/src/composables/__tests__/useDiffScrollSync.spec.ts
new file mode 100644
index 0000000000..ca5cbf1227
--- /dev/null
+++ b/apps/desktop/src/composables/__tests__/useDiffScrollSync.spec.ts
@@ -0,0 +1,41 @@
+import { ref } from "vue";
+import { describe, expect, it } from "vitest";
+import type { DiffHunk } from "@/components/diff/DiffHunkBuilder";
+import { useDiffScrollSync } from "@/composables/useDiffScrollSync";
+
+function createPane(scrollTop: number, scrollLeft: number): HTMLElement {
+ return { scrollTop, scrollLeft } as HTMLElement;
+}
+
+function createScrollSync(leftPane: HTMLElement, rightPane: HTMLElement) {
+ return useDiffScrollSync({
+ container: ref<HTMLElement>(),
+ leftPane: ref<HTMLElement | undefined>(leftPane),
+ rightPane: ref<HTMLElement | undefined>(rightPane),
+ hunks: ref<DiffHunk[]>([]),
+ });
+}
+
+describe("useDiffScrollSync", () => {
+ it("syncs vertical and horizontal scroll from left to right", () => {
+ const leftPane = createPane(100, 240);
+ const rightPane = createPane(0, 0);
+ const { syncScroll } = createScrollSync(leftPane, rightPane);
+
+ syncScroll("left");
+
+ expect(rightPane.scrollTop).toBe(100);
+ expect(rightPane.scrollLeft).toBe(240);
+ });
+
+ it("syncs vertical and horizontal scroll from right to left", () => {
+ const leftPane = createPane(0, 0);
+ const rightPane = createPane(80, 160);
+ const { syncScroll } = createScrollSync(leftPane, rightPane);
+
+ syncScroll("right");
+
+ expect(leftPane.scrollTop).toBe(80);
+ expect(leftPane.scrollLeft).toBe(160);
+ });
+});
diff --git a/apps/desktop/src/composables/useDiffScrollSync.ts b/apps/desktop/src/composables/useDiffScrollSync.ts
index 48cc79e24b..5a63ab9bb7 100644
--- a/apps/desktop/src/composables/useDiffScrollSync.ts
+++ b/apps/desktop/src/composables/useDiffScrollSync.ts
@@ -18,6 +18,7 @@ export function useDiffScrollSync({ container, leftPane, rightPane, hunks }: Use
if (!source || !target) return;
isSyncingScroll.value = true;
target.scrollTop = source.scrollTop;
+ target.scrollLeft = source.scrollLeft;
isSyncingScroll.value = false;
}