fix(sidebar): keep object browser scroll after sql generation
This commit is contained in:
1 parent
e619b70d5d
commit
f9f61cf397
2 files changed
+39
No files matched your search
@@ -445,6 +445,16 @@ function onObjectsScroll() {
|
||||
});
|
||||
}
|
||||
|
||||
function flushObjectBrowserViewport() {
|
||||
if (viewportFrame) {
|
||||
window.cancelAnimationFrame(viewportFrame);
|
||||
viewportFrame = 0;
|
||||
}
|
||||
const el = scrollerElement();
|
||||
if (!el) return;
|
||||
emitViewportChange(el.scrollTop);
|
||||
}
|
||||
|
||||
function applyObjectBrowserScrollTop(scrollTop: number) {
|
||||
const scroller = activeScroller();
|
||||
if (scroller && !(scroller instanceof HTMLElement)) {
|
||||
@@ -1436,6 +1446,7 @@ async function onEventSaved(savedName: string) {
|
||||
}
|
||||
|
||||
async function openNewQuery(row: ObjectBrowserRow) {
|
||||
flushObjectBrowserViewport();
|
||||
const schema = row.schema || selectedSchema.value;
|
||||
const tabId = queryStore.createTab(props.connection.id, props.database, row.name, "query", schema, undefined, props.catalog);
|
||||
queryStore.updateSql(
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const source = readFileSync(new URL("../ObjectBrowser.vue", import.meta.url), "utf8");
|
||||
|
||||
function functionBody(name: string): string {
|
||||
const signature = new RegExp(`(?:async\\s+)?function\\s+${name}\\s*\\([^)]*\\)\\s*(?::\\s*[^\\{]+)?\\{`, "m").exec(source);
|
||||
if (!signature) throw new Error(`Missing function ${name}`);
|
||||
const bodyStart = signature.index + signature[0].length;
|
||||
let depth = 1;
|
||||
for (let index = bodyStart; index < source.length; index += 1) {
|
||||
if (source[index] === "{") depth += 1;
|
||||
else if (source[index] === "}") depth -= 1;
|
||||
if (depth === 0) return source.slice(bodyStart, index);
|
||||
}
|
||||
throw new Error(`Unclosed function ${name}`);
|
||||
}
|
||||
|
||||
describe("ObjectBrowser viewport persistence", () => {
|
||||
it("flushes the latest scroll position before generating SQL", () => {
|
||||
const body = functionBody("openNewQuery");
|
||||
const flushIndex = body.indexOf("flushObjectBrowserViewport();");
|
||||
const createTabIndex = body.indexOf("queryStore.createTab");
|
||||
|
||||
expect(flushIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(createTabIndex).toBeGreaterThan(flushIndex);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user