Skip to content

Commit 472898d

Browse files
Merge pull request #533 from lukecotter/feat-find-incorrect-totals
feat: ensure that the findwidget shows correct totals
2 parents edca048 + 3366127 commit 472898d

4 files changed

Lines changed: 34 additions & 16 deletions

File tree

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,11 @@ export class CalltreeView extends LitElement {
554554
const cellElem = cell.getElement();
555555
const row = cell.getRow();
556556
// @ts-expect-error: _row is private. This is temporary and I will patch the text wrap behaviour in the library.
557-
const treeLevel = row._row.modules.dataTree.index;
557+
const dataTree = row._row.modules.dataTree;
558+
if (!dataTree) {
559+
return '';
560+
}
561+
const treeLevel = dataTree?.index;
558562
childIndent ??= row.getTable().options.dataTreeChildIndent || 0;
559563
const levelIndent = treeLevel * childIndent;
560564
cellElem.style.paddingLeft = `${levelIndent + 4}px`;
@@ -728,12 +732,17 @@ export class CalltreeView extends LitElement {
728732
const len = rows.length;
729733
for (let i = 0; i < len; i++) {
730734
const row = rows[i];
731-
if (!row) {
735+
//@ts-expect-error This is private to tabulator, but we have no other choice atm.
736+
if (!row?._getSelf().modules?.dataTree) {
732737
continue;
733738
}
734739

735-
expand ? row.treeExpand() : row.treeCollapse();
736-
this._expandCollapseAll(row.getTreeChildren(), expand);
740+
if (expand) {
741+
row.treeExpand();
742+
} else {
743+
row.treeCollapse();
744+
}
745+
this._expandCollapseAll(row.getTreeChildren() ?? [], expand);
737746
}
738747
}
739748

@@ -793,7 +802,7 @@ export class CalltreeView extends LitElement {
793802
if (timeStamp === node.timestamp) {
794803
return row;
795804
} else if (isInRange) {
796-
return this._findByTime(row.getTreeChildren(), timeStamp);
805+
return this._findByTime(row.getTreeChildren() ?? [], timeStamp);
797806
}
798807
// Otherwise, look in the left or right half
799808
else if (timeStamp > endTime) {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ export class Find extends Module {
3838

3939
const flatten = (row: RowComponent): RowComponent[] => {
4040
const mergedArray = [row];
41-
row
42-
.getTreeChildren()
43-
.flatMap(flatten)
44-
.forEach((child) => {
45-
mergedArray.push(child);
46-
});
41+
(row.getTreeChildren() ?? []).flatMap(flatten).forEach((child) => {
42+
mergedArray.push(child);
43+
});
4744
return mergedArray;
4845
};
4946

@@ -137,9 +134,14 @@ export function formatter(row: RowComponent, findArgs: FindArgs) {
137134
}
138135

139136
const data = row.getData();
137+
const highlights = {
138+
indexes: data.highlightIndexes,
139+
currentMatch: 0,
140+
};
141+
140142
row.getCells().forEach((cell) => {
141143
const cellElem = cell.getElement();
142-
_highlightText(cellElem, findArgs, { indexes: data.highlightIndexes, currentMatch: 0 });
144+
_highlightText(cellElem, findArgs, highlights);
143145
});
144146

145147
//@ts-expect-error This is private to tabulator, but we have no other choice atm.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class MiddleRowFocus extends Module {
113113

114114
return this._findClosestActiveSibling(mid, rows, displayRows);
115115
} else if (timeStamp >= node.timestamp && timeStamp <= endTime) {
116-
const childMatch = this._findClosestActive(row.getTreeChildren(), timeStamp);
116+
const childMatch = this._findClosestActive(row.getTreeChildren() ?? [], timeStamp);
117117
if (childMatch) {
118118
return childMatch;
119119
}

log-viewer/modules/timeline/Timeline.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ let findArgs: { text: string; count: number; options: { matchCase: boolean } } =
170170
count: 1,
171171
options: { matchCase: false },
172172
};
173+
let totalMatches = 0;
173174

174175
function getMaxDepth(nodes: LogLine[]) {
175176
const result = new Map<number, LogLine[]>();
@@ -918,6 +919,9 @@ function handleScroll(evt: WheelEvent) {
918919
function _findOnTimeline(
919920
e: CustomEvent<{ text: string; count: number; options: { matchCase: boolean } }>,
920921
) {
922+
if (!isVisible && !totalMatches) {
923+
return;
924+
}
921925
_hideTooltip();
922926

923927
const newFindArgs = JSON.parse(JSON.stringify(e.detail));
@@ -938,10 +942,13 @@ function _findOnTimeline(
938942
borderRenderQueue.clear();
939943
nodesToRectangles(timelineRoot.children as Method[]);
940944
const findResults = borderRenderQueue.get(findMatchColor) || [];
945+
totalMatches = findResults.length;
941946

942-
document.dispatchEvent(
943-
new CustomEvent('lv-find-results', { detail: { totalMatches: findResults.length } }),
944-
);
947+
if (!clearHighlights) {
948+
document.dispatchEvent(
949+
new CustomEvent('lv-find-results', { detail: { totalMatches: totalMatches } }),
950+
);
951+
}
945952
}
946953

947954
const findResults = borderRenderQueue.get(findMatchColor) || [];

0 commit comments

Comments
 (0)