fix: find highlight disappears on clicking the cell (#14342)

* update content only when changed

* maintain thr highlight on rerenders

* pr comments
This commit is contained in:
Maddy
2021-03-01 13:43:41 -08:00
committed by GitHub
parent 9432330c46
commit 14b9628b52

View File

@@ -93,6 +93,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
public readonly onDidClickLink = this._onDidClickLink.event;
public previewFeaturesEnabled: boolean = false;
public doubleClickEditEnabled: boolean;
private _highlightRange: NotebookRange;
constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
@@ -238,6 +239,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
outputElement.style.lineHeight = this.markdownPreviewLineHeight.toString();
this.cellModel.renderedOutputTextContent = this.getRenderedTextOutput();
outputElement.focus();
this.addDecoration();
}
}
}
@@ -345,15 +347,18 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
public deltaDecorations(newDecorationRange: NotebookRange, oldDecorationRange: NotebookRange): void {
if (oldDecorationRange) {
this._highlightRange = oldDecorationRange === this._highlightRange ? undefined : this._highlightRange;
this.removeDecoration(oldDecorationRange);
}
if (newDecorationRange) {
this._highlightRange = newDecorationRange;
this.addDecoration(newDecorationRange);
}
}
private addDecoration(range: NotebookRange): void {
private addDecoration(range?: NotebookRange): void {
range = range ?? this._highlightRange;
if (range && this.output && this.output.nativeElement) {
let markAllOccurances = new Mark(this.output.nativeElement); // to highlight all occurances in the element.
let elements = this.getHtmlElements();