Skip to content

Commit 7eeeb8a

Browse files
committed
refactor: split clear highlight + search logic
1 parent c6a3625 commit 7eeeb8a

3 files changed

Lines changed: 44 additions & 47 deletions

File tree

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

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

126
export class Find extends Module {
137
static moduleName = 'FindModule';
@@ -53,51 +47,50 @@ export class Find extends Module {
5347
const regex = new RegExp(searchString, `g${findArgs.options.matchCase ? '' : 'i'}`);
5448

5549
tbl.blockRedraw();
56-
let totalMatches = 0;
57-
const rowsToReformat = [];
58-
const len = flattenedRows.length;
59-
for (let i = 0; i < len; i++) {
60-
const row = flattenedRows[i];
61-
if (!row) {
62-
continue;
63-
}
64-
65-
let clearHighlight = false;
50+
for (const row of flattenedRows) {
6651
const data = row.getData();
67-
if (data.highlightIndexes?.length) {
68-
clearHighlight = true;
69-
rowsToReformat.push(row);
52+
if (data.highlightIndexes?.length > 0) {
53+
data.highlightIndexes.length = 0;
54+
row.reformat();
55+
} else if (!data.highlightIndexes) {
56+
data.highlightIndexes = [];
7057
}
58+
}
59+
tbl.restoreRedraw();
7160

72-
data.highlightIndexes = [];
73-
74-
if (!searchString) {
75-
continue;
76-
}
77-
let reformat = false;
78-
79-
row.getCells().forEach((cell: CellComponent) => {
80-
const elem = cell.getElement();
81-
const matchCount = this._countMatches(elem, findArgs, regex);
82-
if (matchCount) {
83-
const kLen = matchCount;
84-
for (let k = 0; k < kLen; k++) {
85-
totalMatches++;
86-
data.highlightIndexes.push(totalMatches);
87-
result.matchIndexes[totalMatches] = row;
88-
}
89-
reformat = true;
61+
await new Promise((resolve) => requestAnimationFrame(resolve));
62+
let totalMatches = 0;
63+
if (searchString) {
64+
const rowsToReformat = new Set<RowComponent>();
65+
const len = flattenedRows.length;
66+
for (let i = 0; i < len; i++) {
67+
const row = flattenedRows[i];
68+
if (!row) {
69+
continue;
9070
}
91-
});
9271

93-
if (reformat && !clearHighlight) {
94-
rowsToReformat.push(row);
72+
const data = row.getData();
73+
data.highlightIndexes = [];
74+
row.getCells().forEach((cell) => {
75+
const elem = cell.getElement();
76+
const matchCount = this._countMatches(elem, findArgs, regex);
77+
if (matchCount) {
78+
const kLen = matchCount;
79+
for (let k = 0; k < kLen; k++) {
80+
totalMatches++;
81+
data.highlightIndexes.push(totalMatches);
82+
result.matchIndexes[totalMatches] = row;
83+
}
84+
rowsToReformat.add(row);
85+
}
86+
});
9587
}
88+
tbl.blockRedraw();
89+
rowsToReformat.forEach((row) => {
90+
row?.reformat();
91+
});
92+
tbl.restoreRedraw();
9693
}
97-
rowsToReformat.forEach((row) => {
98-
row?.reformat();
99-
});
100-
tbl.restoreRedraw();
10194

10295
result.totalMatches = totalMatches;
10396
return result;

log-viewer/modules/components/database-view/DMLView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ export class DMLView extends LitElement {
159159
this.dmlTable?.download('csv', 'dml.csv', { bom: true, delimiter: ',' });
160160
}
161161

162-
_findEvt = ((event: FindEvt) => this._find(event)) as EventListener;
162+
_findEvt = ((event: FindEvt) => {
163+
this._find(event);
164+
}) as EventListener;
163165

164166
_dmlGroupBy(event: Event) {
165167
const target = event.target as HTMLInputElement;

log-viewer/modules/components/database-view/SOQLView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ export class SOQLView extends LitElement {
191191
this.soqlTable?.download('csv', 'soql.csv', { bom: true, delimiter: ',' });
192192
}
193193

194-
_findEvt = ((event: FindEvt) => this._find(event)) as EventListener;
194+
_findEvt = ((event: FindEvt) => {
195+
this._find(event);
196+
}) as EventListener;
195197

196198
_soqlGroupBy(event: Event) {
197199
if (!this.soqlTable) {

0 commit comments

Comments
 (0)