Skip to content

Commit a81e577

Browse files
Merge pull request #595 from lukecotter/feat-search-filtered-rows-only
feat: call tree search within filtered visible rows only
2 parents f07cdb1 + 0f45dff commit a81e577

5 files changed

Lines changed: 71 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Highlight and copy text to clipboard: Call Tree, Analysis and Database views ([#504][#504]).
2222
- Previously the highlighted text would be immediately cleared.
2323
- Sharper timeline rending on HiDPI displays ([#588][#588]).
24+
- Call Tree search will now only search in the visible filtered rows ([#539]).
2425

2526
### Fixed
2627

@@ -394,6 +395,7 @@ Skipped due to adopting odd numbering for pre releases and even number for relea
394395
[#590]: https://github.com/certinia/debug-log-analyzer/issues/590
395396
[#592]: https://github.com/certinia/debug-log-analyzer/issues/592
396397
[#93]: https://github.com/certinia/debug-log-analyzer/issues/93
398+
[#539]: https://github.com/certinia/debug-log-analyzer/issues/539
397399

398400
<!-- 1.16.1 -->
399401

log-viewer/modules/components/calltree-view/CalltreeView.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export class CalltreeView extends LitElement {
302302
}
303303
this.calltreeTable.blockRedraw();
304304
this._expandCollapseAll(this.calltreeTable.getRows(), true);
305+
this.calltreeTable.element?.querySelector<HTMLElement>('.tabulator-tableholder')?.focus();
305306
this.calltreeTable.restoreRedraw();
306307
}
307308

@@ -311,6 +312,7 @@ export class CalltreeView extends LitElement {
311312
}
312313
this.calltreeTable.blockRedraw();
313314
this._expandCollapseAll(this.calltreeTable.getRows(), false);
315+
this.calltreeTable.element?.querySelector<HTMLElement>('.tabulator-tableholder')?.focus();
314316
this.calltreeTable.restoreRedraw();
315317
}
316318

@@ -343,15 +345,12 @@ export class CalltreeView extends LitElement {
343345
this.calltreeTable.goToRow(treeRow, { scrollIfVisible: true, focusRow: true });
344346
}
345347

346-
_find(
347-
e: CustomEvent<{ text: string; count: number; options: { matchCase: boolean } }>,
348-
canClearOverride = true,
349-
) {
348+
_find(e: CustomEvent<{ text: string; count: number; options: { matchCase: boolean } }>) {
350349
const isTableVisible = !!this.calltreeTable?.element?.clientHeight;
351350
if (!isTableVisible && !this.totalMatches) {
352351
return;
353352
}
354-
this.canClearSearchHighlights = canClearOverride;
353+
this.canClearSearchHighlights = false;
355354

356355
const newFindArgs = JSON.parse(JSON.stringify(e.detail));
357356
const newSearch =
@@ -360,7 +359,8 @@ export class CalltreeView extends LitElement {
360359
this.findArgs = newFindArgs;
361360

362361
const clearHighlights =
363-
e.type === 'lv-find-close' || (!isTableVisible && newFindArgs.count === 0);
362+
e.type === 'lv-find-close' ||
363+
(this.canClearSearchHighlights && !isTableVisible && newFindArgs.count === 0);
364364
if (clearHighlights) {
365365
newFindArgs.text = '';
366366
}
@@ -377,6 +377,7 @@ export class CalltreeView extends LitElement {
377377
}
378378
}
379379

380+
this.calltreeTable?.blockRedraw();
380381
const currentRow = this.findMap[this.findArgs.count];
381382
const rows = [
382383
currentRow,
@@ -391,6 +392,8 @@ export class CalltreeView extends LitElement {
391392
//@ts-expect-error This is a custom function added in by RowNavigation custom module
392393
this.calltreeTable.goToRow(currentRow, { scrollIfVisible: false, focusRow: false });
393394
}
395+
this.calltreeTable?.restoreRedraw();
396+
this.canClearSearchHighlights = true;
394397
}
395398

396399
_highlight(inputString: string, substring: string) {
@@ -805,7 +808,6 @@ export class CalltreeView extends LitElement {
805808
new CustomEvent('lv-find', {
806809
detail: { text: '', count: 0, options: { matchCase: false } },
807810
}),
808-
false,
809811
);
810812
}
811813

log-viewer/modules/components/calltree-view/module/Find.ts

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/*
22
* Copyright (c) 2024 Certinia Inc. All rights reserved.
33
*/
4-
import { Module, type GroupComponent, type RowComponent, type Tabulator } from 'tabulator-tables';
4+
import {
5+
Module,
6+
type CellComponent,
7+
type GroupComponent,
8+
type RowComponent,
9+
type Tabulator,
10+
} from 'tabulator-tables';
511

612
export class Find extends Module {
713
static moduleName = 'FindModule';
@@ -34,18 +40,9 @@ export class Find extends Module {
3440
return mergedArray;
3541
};
3642

37-
const flatten = (row: RowComponent): RowComponent[] => {
38-
const mergedArray = [row];
39-
(row.getTreeChildren() ?? []).flatMap(flatten).forEach((child) => {
40-
mergedArray.push(child);
41-
});
42-
return mergedArray;
43-
};
44-
45-
// Only get the currently visible rows
4643
const tbl = this.table;
4744
const grps = tbl.getGroups().flatMap(flattenFromGrps);
48-
const flattenedRows = grps.length ? grps : tbl.getRows('active').flatMap(flatten);
45+
const flattenedRows = grps.length ? grps : this._getRows(tbl.getRows('active'));
4946

5047
const findOptions = findArgs.options;
5148
let searchString = findOptions.matchCase ? findArgs.text : findArgs.text.toLowerCase();
@@ -76,7 +73,7 @@ export class Find extends Module {
7673
}
7774
let reformat = false;
7875

79-
row.getCells().forEach((cell) => {
76+
row.getCells().forEach((cell: CellComponent) => {
8077
const elem = cell.getElement();
8178
const matchCount = this._countMatches(elem, findArgs, regex);
8279
if (matchCount) {
@@ -130,6 +127,52 @@ export class Find extends Module {
130127
return count;
131128
}
132129

130+
_getRows(rows: RowComponent[]) {
131+
const isDataTreeEnabled = this.table.modules.dataTree && this.table.options.dataTreeFilter;
132+
if (!isDataTreeEnabled) {
133+
return rows;
134+
}
135+
136+
const children = [];
137+
for (const row of rows) {
138+
children.push(row);
139+
for (const child of this._getFilteredChildren(row)) {
140+
children.push(child);
141+
}
142+
}
143+
return children;
144+
}
145+
146+
_getFilteredChildren(row: RowComponent): RowComponent[] {
147+
const output: RowComponent[] = [];
148+
149+
const filtering = this.table.modules.filter;
150+
const sorting = this.table.options.dataTreeSort ? this.table.modules.sort : null;
151+
let internalChildren = [];
152+
for (const child of row.getTreeChildren()) {
153+
//@ts-expect-error This is private to tabulator, but we have no other choice atm.
154+
internalChildren.push(child._getSelf());
155+
}
156+
internalChildren = filtering.filter(internalChildren);
157+
if (sorting) {
158+
sorting.sort(internalChildren, true);
159+
}
160+
161+
const filteredChildren = [];
162+
for (const internalChild of internalChildren) {
163+
const childComp: RowComponent = internalChild.getComponent();
164+
filteredChildren.push(childComp);
165+
output.push(childComp);
166+
167+
const subChildren = this._getFilteredChildren(childComp);
168+
subChildren.forEach((sub) => {
169+
output.push(sub);
170+
});
171+
}
172+
173+
return output;
174+
}
175+
133176
_clearMatches() {
134177
const matches = this.table.element.querySelectorAll('.currentFindMatch, .findMatch');
135178
for (const elm of matches) {

log-viewer/modules/components/calltree-view/module/MiddleRowFocus.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ export class MiddleRowFocus extends Module {
7575
if (rowToScrollTo) {
7676
this.table.scrollToRow(rowToScrollTo, 'center', true).then(() => {
7777
setTimeout(() => {
78-
if (rowToScrollTo) {
79-
rowToScrollTo
80-
?.getElement()
81-
.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'start' });
82-
}
78+
rowToScrollTo
79+
?.getElement()
80+
.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'start' });
8381
});
8482
});
8583
}

log-viewer/modules/datagrid/module/RowKeyboardNavigation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,10 @@ export class RowKeyboardNavigation extends Module {
4848

4949
rowExpandedToggled(row: RowComponent, _level: number) {
5050
const table = row.getTable();
51-
this.tableHolder ??= table.element.querySelector('.tabulator-tableholder') as HTMLElement;
52-
53-
const selectedRow = table.getSelectedRows()[0];
54-
if (!selectedRow) {
51+
const selectedRows = table.getSelectedRows();
52+
if (!selectedRows.length) {
5553
row.select();
5654
}
57-
this.tableHolder?.focus();
5855
}
5956

6057
rowClick(event: UIEvent, row: RowComponent) {

0 commit comments

Comments
 (0)