Start to refactor search highlighting to better match hecto implementation
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
This commit is contained in:
parent
ce7a60332a
commit
d405880ce8
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user