diff --git a/src/common/document.ts b/src/common/document.ts index 5ab5856..69ed56d 100644 --- a/src/common/document.ts +++ b/src/common/document.ts @@ -174,6 +174,12 @@ export class Document { this.dirty = true; } + public highlight(searchMatch?: string): void { + this.#rows.forEach((row) => { + row.update(searchMatch); + }); + } + /** * Delete the specified row * @param at - the index of the row to delete diff --git a/src/common/row.ts b/src/common/row.ts index 0a30dc2..173621d 100644 --- a/src/common/row.ts +++ b/src/common/row.ts @@ -189,14 +189,32 @@ export class Row { return this.chars.join(''); } - public update(): void { + public update(searchMatch?: string): void { const newString = this.chars.join('').replaceAll( '\t', ' '.repeat(SCROLL_TAB_SIZE), ); 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 { @@ -220,19 +238,6 @@ export class Row { 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;