Skip to content

Commit c264a8d

Browse files
committed
fix: improve the reliability of scroll when rows are clicked
The behaviour of keeping the grouped and normal rows that are clicked in focus should be far more reliable. This should reduce the jumping effect that can be seen with tables of a large height.
1 parent 12eb65c commit c264a8d

2 files changed

Lines changed: 38 additions & 43 deletions

File tree

log-viewer/modules/database-view/DatabaseView.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
@import '../datagrid/style/DataGrid.scss';
22

3-
#db-container {
4-
overflow: scroll;
5-
}
6-
#db-dml-table,
7-
#db-soql-table {
8-
margin-bottom: 1rem;
9-
height: 100%;
10-
}
113
.row__details-container {
124
padding: 4px 0px 4px 0px;
135
background-color: var(--vscode-editorHoverWidget-background);

log-viewer/modules/database-view/DatabaseView.ts

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export class DatabaseView extends LitElement {
9595
width: 100%;
9696
min-height: 0%;
9797
min-width: 0%;
98+
margin-bottom: 1rem;
99+
display: flex;
100+
flex-direction: column;
98101
}
99102
`,
100103
];
@@ -320,15 +323,13 @@ function renderDMLTable(dmlTableContainer: HTMLElement, dmlLines: DMLBeginLine[]
320323
}
321324
});
322325

323-
dmlTable.on('groupVisibilityChanged', (group: GroupComponent, visible: boolean) => {
324-
const firstRow = visible ? group.getRows()[0] : group.getRows()[0].getPrevRow();
325-
if (firstRow) {
326-
// @ts-expect-error it has 2 params
327-
firstRow.scrollTo('center', true).then(() => {
328-
firstRow
329-
.getElement()
330-
.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'start' });
331-
});
326+
dmlTable.on('groupVisibilityChanged', (group: GroupComponent, _visible: boolean) => {
327+
const groupToFocus = group.getElement() ? group : findGroup(soqlTable, group.getKey());
328+
329+
if (groupToFocus) {
330+
groupToFocus
331+
.getElement()
332+
.scrollIntoView({ behavior: 'instant', block: 'center', inline: 'start' });
332333
}
333334
});
334335

@@ -337,18 +338,13 @@ function renderDMLTable(dmlTableContainer: HTMLElement, dmlLines: DMLBeginLine[]
337338
if (!(data.timestamp && data.dml)) {
338339
return;
339340
}
340-
const origRowHeight = row.getElement().offsetHeight;
341341

342+
const origRowHeight = row.getElement().offsetHeight;
342343
row.treeToggle();
343-
row.getCell('soql').getElement().style.height = origRowHeight + 'px';
344+
row.getCell('dml').getElement().style.height = origRowHeight + 'px';
344345

345-
const nextRow = row.getNextRow() || row.getTreeChildren()[0];
346-
if (nextRow) {
347-
// @ts-expect-error it has 2 params
348-
nextRow.scrollTo('center', true).then(() => {
349-
nextRow.getElement().scrollIntoView({ behavior: 'auto', block: 'center', inline: 'start' });
350-
});
351-
}
346+
row &&
347+
row.getElement().scrollIntoView({ behavior: 'instant', block: 'center', inline: 'start' });
352348
});
353349
}
354350

@@ -598,15 +594,13 @@ function renderSOQLTable(soqlTableContainer: HTMLElement, soqlLines: SOQLExecute
598594
}
599595
});
600596

601-
soqlTable.on('groupVisibilityChanged', (group: GroupComponent, visible: boolean) => {
602-
const firstRow = visible ? group.getRows()[0] : group.getRows()[0].getPrevRow();
603-
if (firstRow) {
604-
// @ts-expect-error it has 2 params
605-
firstRow.scrollTo('center', true).then(() => {
606-
firstRow
607-
.getElement()
608-
.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'start' });
609-
});
597+
soqlTable.on('groupVisibilityChanged', (group: GroupComponent, _visible: boolean) => {
598+
const groupToFocus = group.getElement() ? group : findGroup(soqlTable, group.getKey());
599+
600+
if (groupToFocus) {
601+
groupToFocus
602+
.getElement()
603+
.scrollIntoView({ behavior: 'instant', block: 'center', inline: 'start' });
610604
}
611605
});
612606

@@ -617,17 +611,11 @@ function renderSOQLTable(soqlTableContainer: HTMLElement, soqlLines: SOQLExecute
617611
}
618612

619613
const origRowHeight = row.getElement().offsetHeight;
620-
621614
row.treeToggle();
622615
row.getCell('soql').getElement().style.height = origRowHeight + 'px';
623616

624-
const nextRow = row.getNextRow() || row.getTreeChildren()[0];
625-
if (nextRow) {
626-
// @ts-expect-error it has 2 params
627-
nextRow.scrollTo('center', true).then(() => {
628-
nextRow.getElement().scrollIntoView({ behavior: 'auto', block: 'center', inline: 'start' });
629-
});
630-
}
617+
row &&
618+
row.getElement().scrollIntoView({ behavior: 'instant', block: 'center', inline: 'start' });
631619
});
632620
}
633621

@@ -689,3 +677,18 @@ function downlodEncoder(defaultFileName: string) {
689677
return new Blob([fileContents], { type: mimeType });
690678
};
691679
}
680+
681+
function findGroup(table: Tabulator, groupKey: string): GroupComponent | null {
682+
let foundGroup = null;
683+
const groups = soqlTable.getGroups();
684+
let len = groups?.length - 1 || 0;
685+
while (len >= 0 && !foundGroup) {
686+
const toSearch = groups[len];
687+
if (toSearch.getKey() === groupKey) {
688+
foundGroup = toSearch;
689+
break;
690+
}
691+
len--;
692+
}
693+
return foundGroup;
694+
}

0 commit comments

Comments
 (0)