Start to refactor search highlighting to better match hecto implementation
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2024-06-26 15:55:47 -04:00
parent ce7a60332a
commit d405880ce8
2 changed files with 26 additions and 15 deletions

View File

@ -174,6 +174,12 @@ export class Document {
this.dirty = true; this.dirty = true;
} }
public highlight(searchMatch?: string): void {
this.#rows.forEach((row) => {
row.update(searchMatch);
});
}
/** /**
* Delete the specified row * Delete the specified row
* @param at - the index of the row to delete * @param at - the index of the row to delete

View File

@ -189,14 +189,32 @@ export class Row {
return this.chars.join(''); return this.chars.join('');
} }
public update(): void { public update(searchMatch?: string): void {
const newString = this.chars.join('').replaceAll( const newString = this.chars.join('').replaceAll(
'\t', '\t',
' '.repeat(SCROLL_TAB_SIZE), ' '.repeat(SCROLL_TAB_SIZE),
); );
this.rchars = strChars(newString); this.rchars = strChars(newString);
this.highlight(); this.highlight(searchMatch);
}
public highlight(searchMatch?: string): void {
const highlighting = [];
if (some(searchMatch)) {
// TODO: highlight search here
}
for (const ch of this.rchars) {
if (isAsciiDigit(ch)) {
highlighting.push(HighlightType.Number);
} else {
highlighting.push(HighlightType.None);
}
}
this.hl = highlighting;
} }
public render(offset: number, len: number): string { public render(offset: number, len: number): string {
@ -220,19 +238,6 @@ export class Row {
return result; return result;
} }
private highlight(): void {
const highlighting = [];
for (const ch of this.rchars) {
if (isAsciiDigit(ch)) {
highlighting.push(HighlightType.Number);
} else {
highlighting.push(HighlightType.None);
}
}
this.hl = highlighting;
}
} }
export default Row; export default Row;