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 8c402db774..8452cffe9b 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts @@ -381,16 +381,18 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges { markAllOccurances.mark(searchString, { className: findHighlightClass }); - elementContainingText.scrollIntoView({ behavior: 'smooth' }); } } markCurrent.markRanges([{ start: range.startColumn - 1, //subtracting 1 since markdown html is 0 indexed. length: range.endColumn - range.startColumn }], { - className: findRangeSpecificClass + className: findRangeSpecificClass, + each: function (node, range) { + // node is the marked DOM element + node.scrollIntoView({ behavior: 'smooth', block: 'center' }); + } }); - elementContainingText.scrollIntoView({ behavior: 'smooth' }); } } } diff --git a/src/sql/workbench/contrib/notebook/browser/find/notebookFindModel.ts b/src/sql/workbench/contrib/notebook/browser/find/notebookFindModel.ts index 0c2a2a6858..4527f6dd48 100644 --- a/src/sql/workbench/contrib/notebook/browser/find/notebookFindModel.ts +++ b/src/sql/workbench/contrib/notebook/browser/find/notebookFindModel.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Disposable } from 'vs/base/common/lifecycle'; -import { ICellModel, INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces'; +import { CellEditModes, ICellModel, INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces'; import { INotebookFindModel } from 'sql/workbench/contrib/notebook/browser/models/notebookFindModel'; import { Event, Emitter } from 'vs/base/common/event'; import * as types from 'vs/base/common/types'; @@ -535,7 +535,7 @@ export class NotebookFindModel extends Disposable implements INotebookFindModel private searchFn(cell: ICellModel, exp: string, matchCase: boolean = false, wholeWord: boolean = false, maxMatches?: number): NotebookRange[] { let findResults: NotebookRange[] = []; - if (cell.cellType === 'markdown' && cell.isEditMode && typeof cell.source !== 'string') { + if (cell.cellType === 'markdown' && (cell.showMarkdown || cell.currentMode === CellEditModes.SPLIT) && typeof cell.source !== 'string') { let cellSource = cell.source; for (let j = 0; j < cellSource.length; j++) { let findStartResults = this.search(cellSource[j], exp, matchCase, wholeWord, maxMatches - findResults.length); @@ -546,7 +546,8 @@ export class NotebookFindModel extends Disposable implements INotebookFindModel }); } } - let cellVal = cell.cellType === 'markdown' ? cell.renderedOutputTextContent : cell.source; + // if it's markdown cell in Markdown only mode, don't search on renderedOutput. + let cellVal = cell.cellType === 'markdown' ? (cell.currentMode === CellEditModes.SPLIT || !cell.showMarkdown ? cell.renderedOutputTextContent : undefined) : cell.source; if (cellVal) { if (typeof cellVal === 'string') { let findStartResults = this.search(cellVal, exp, matchCase, wholeWord, maxMatches); @@ -557,7 +558,7 @@ export class NotebookFindModel extends Disposable implements INotebookFindModel } else { for (let j = 0; j < cellVal.length; j++) { - let cellValFormatted = cell.cellType === 'markdown' ? this.cleanMarkdownLinks(cellVal[j]) : cellVal[j]; + let cellValFormatted = cellVal[j]; let findStartResults = this.search(cellValFormatted, exp, matchCase, wholeWord, maxMatches - findResults.length); findStartResults.forEach(start => { // lineNumber: j+1 since notebook editors aren't zero indexed. @@ -606,12 +607,6 @@ export class NotebookFindModel extends Disposable implements INotebookFindModel return findResults; } - // In markdown links are defined as [Link Text](https://url/of/the/text). when searching for text we shouldn't - // look for the values inside the (), below regex replaces that with just the Link Text. - cleanMarkdownLinks(cellSrc: string): string { - return cellSrc.replace(/(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, '$1'); - } - clearFind(): void { this._findArray = new Array(); this._findIndex = 0; diff --git a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts index 188115eb86..15a31702a6 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts @@ -371,7 +371,14 @@ export class NotebookEditor extends EditorPane implements IFindNotebookControlle }; this._notebookModel.cells?.forEach(cell => { this._register(cell.onCellModeChanged((state) => { - this._onFindStateChange(changeEvent).catch(onUnexpectedError); + if (state) { + this._onFindStateChange(changeEvent).catch(onUnexpectedError); + } + })); + this._register(cell.onCellMarkdownModeChanged(e => { + if (e) { + this._onFindStateChange(changeEvent).catch(onUnexpectedError); + } })); }); this._register(this._notebookModel.contentChanged(e => { @@ -449,9 +456,10 @@ export class NotebookEditor extends EditorPane implements IFindNotebookControlle private _setCurrentFindMatch(match: NotebookRange): void { if (match) { - this._notebookModel.updateActiveCell(match.cell); + if (this._notebookModel.activeCell !== match.cell) { + this._notebookModel.updateActiveCell(match.cell); + } this._findDecorations.setCurrentFindMatch(match); - this.setSelection(match); } } diff --git a/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts b/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts index e5b288b915..985af6fe59 100644 --- a/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts +++ b/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts @@ -81,6 +81,10 @@ class NotebookModelStub extends stubs.NotebookModelStub { // When relevant a mock is used to intercept this call to do any verifications or run // any code relevant for testing in the context of the test. } + + get activeCell(): ICellModel { + return {}; + } } suite('Test class NotebookEditor:', () => {