From 14b9628b527426189f37a7eb2a35b828d72706ad Mon Sep 17 00:00:00 2001 From: Maddy <12754347+MaddyDev@users.noreply.github.com> Date: Mon, 1 Mar 2021 13:43:41 -0800 Subject: [PATCH] fix: find highlight disappears on clicking the cell (#14342) * update content only when changed * maintain thr highlight on rerenders * pr comments --- .../notebook/browser/cellViews/textCell.component.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts index e1beaac1e0..7522fdc619 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts @@ -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();