Skip to content

Commit de4083a

Browse files
authored
Fix clearing hoghligh functionality when a user turn the feature off (#108)
1 parent c7a85d8 commit de4083a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/ng-generate/components/table/generators/directives/highlight/files/__name@dasherize__.directive.ts.template

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,19 @@ export class <%= classify(name) %>Directive implements OnChanges, OnInit {
4444

4545
ngOnChanges(changes: HighlightSimpleChanges) {
4646
if ((changes.highlight && !changes.highlight.firstChange) || (changes.caseSensitive && !changes.caseSensitive.firstChange)) {
47-
if (this._selected) {
48-
this.transformText();
49-
}
47+
this.handleHighlightText();
5048
}
5149
}
5250

5351
ngOnInit(): void {
52+
this.handleHighlightText();
53+
}
54+
55+
private handleHighlightText(): void {
5456
if (this._selected) {
55-
this.transformText();
57+
this.transformText();
58+
} else if (this.isStringHighlighted) {
59+
this.clearHighlights();
5660
}
5761
}
5862

@@ -149,4 +153,13 @@ export class <%= classify(name) %>Directive implements OnChanges, OnInit {
149153
result += this.highlightSource?.substring(lastIndex);
150154
return result;
151155
}
156+
157+
private get isStringHighlighted(): boolean {
158+
return !!this.el.nativeElement.querySelector('mark');
159+
}
160+
161+
private clearHighlights(): void {
162+
const content = this.sanitizer.sanitize(SecurityContext.STYLE, this.el.nativeElement.innerText);
163+
(this.el.nativeElement as HTMLElement).innerHTML = content;
164+
}
152165
}

0 commit comments

Comments
 (0)