mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 01:25:38 -05:00
fix the find highlight issues (#15149)
* register mode changes, remove cleanMarkdownLinks * fixes * test fixes and scroll to center change
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<NotebookRange>();
|
||||
this._findIndex = 0;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <ICellModel>{};
|
||||
}
|
||||
}
|
||||
|
||||
suite('Test class NotebookEditor:', () => {
|
||||
|
||||
Reference in New Issue
Block a user