mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 01:25:37 -05:00
Fix/search text cell on edit (#9685)
* find in text cell changes * remove prev decorations * update find index on cell edit * added test * addressed comments * emit error
This commit is contained in:
@@ -25,8 +25,7 @@ import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/no
|
||||
import { ISanitizer, defaultSanitizer } from 'sql/workbench/services/notebook/browser/outputs/sanitizer';
|
||||
import { CellToggleMoreActions } from 'sql/workbench/contrib/notebook/browser/cellToggleMoreActions';
|
||||
import { CodeComponent } from 'sql/workbench/contrib/notebook/browser/cellViews/code.component';
|
||||
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
|
||||
import { NotebookRange } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { NotebookRange, ICellEditorProvider } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { IColorTheme } from 'vs/platform/theme/common/themeService';
|
||||
|
||||
export const TEXT_SELECTOR: string = 'text-cell-component';
|
||||
@@ -106,6 +105,14 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
}));
|
||||
}
|
||||
|
||||
public get cellEditors(): ICellEditorProvider[] {
|
||||
let editors: ICellEditorProvider[] = [];
|
||||
if (this.markdowncodeCell) {
|
||||
editors.push(...this.markdowncodeCell.toArray());
|
||||
}
|
||||
return editors;
|
||||
}
|
||||
|
||||
//Gets sanitizer from ISanitizer interface
|
||||
private get sanitizer(): ISanitizer {
|
||||
if (this._sanitizer) {
|
||||
@@ -121,15 +128,6 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
get activeCellId(): string {
|
||||
return this._activeCellId;
|
||||
}
|
||||
/**
|
||||
* Returns the code editor of makrdown cell in edit mode.
|
||||
*/
|
||||
getEditor(): BaseTextEditor | undefined {
|
||||
if (this.markdowncodeCell.length > 0) {
|
||||
return this.markdowncodeCell.first.getEditor();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private setLoading(isLoading: boolean): void {
|
||||
this.cellModel.loaded = !isLoading;
|
||||
@@ -231,6 +229,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
|
||||
public toggleEditMode(editMode?: boolean): void {
|
||||
this.isEditMode = editMode !== undefined ? editMode : !this.isEditMode;
|
||||
this.cellModel.isEditMode = this.isEditMode;
|
||||
this.updateMoreActions();
|
||||
this.updatePreview();
|
||||
this._changeRef.detectChanges();
|
||||
|
||||
@@ -48,4 +48,6 @@ export interface INotebookFindModel {
|
||||
findExpression: string;
|
||||
/** Emit event when the find count changes */
|
||||
onFindCountChange: Event<number>;
|
||||
/** Get the find index when range is given*/
|
||||
getIndexByRange(range: NotebookRange): number;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
||||
@ViewChild('bookNav', { read: ElementRef }) private bookNav: ElementRef;
|
||||
|
||||
@ViewChildren(CodeCellComponent) private codeCells: QueryList<CodeCellComponent>;
|
||||
@ViewChildren(TextCellComponent) private textCells: QueryList<ICellEditorProvider>;
|
||||
@ViewChildren(TextCellComponent) private textCells: QueryList<TextCellComponent>;
|
||||
|
||||
private _model: NotebookModel;
|
||||
protected _actionBar: Taskbar;
|
||||
@@ -150,6 +150,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
||||
this.codeCells.toArray().forEach(cell => editors.push(...cell.cellEditors));
|
||||
}
|
||||
if (this.textCells) {
|
||||
this.textCells.toArray().forEach(cell => editors.push(...cell.cellEditors));
|
||||
editors.push(...this.textCells.toArray());
|
||||
}
|
||||
return editors;
|
||||
@@ -157,12 +158,12 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
||||
|
||||
public deltaDecorations(newDecorationRange: NotebookRange, oldDecorationRange: NotebookRange): void {
|
||||
if (newDecorationRange && newDecorationRange.cell && newDecorationRange.cell.cellType === 'markdown') {
|
||||
let cell = this.cellEditors.filter(c => c.cellGuid() === newDecorationRange.cell.cellGuid)[0];
|
||||
cell.deltaDecorations(newDecorationRange, undefined);
|
||||
let cell = this.cellEditors.filter(c => c.cellGuid() === newDecorationRange.cell.cellGuid);
|
||||
cell[cell.length - 1].deltaDecorations(newDecorationRange, undefined);
|
||||
}
|
||||
if (oldDecorationRange && oldDecorationRange.cell && oldDecorationRange.cell.cellType === 'markdown') {
|
||||
let cell = this.cellEditors.filter(c => c.cellGuid() === oldDecorationRange.cell.cellGuid)[0];
|
||||
cell.deltaDecorations(undefined, oldDecorationRange);
|
||||
let cell = this.cellEditors.filter(c => c.cellGuid() === oldDecorationRange.cell.cellGuid);
|
||||
cell[cell.length - 1].deltaDecorations(undefined, oldDecorationRange);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,9 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle
|
||||
let editorImpl = this._notebookService.findNotebookEditor(this.notebookInput.notebookUri);
|
||||
if (editorImpl) {
|
||||
let cellEditorProvider = editorImpl.cellEditors.filter(c => c.cellGuid() === cellGuid)[0];
|
||||
return cellEditorProvider ? cellEditorProvider.getEditor() : undefined;
|
||||
if (cellEditorProvider) {
|
||||
return cellEditorProvider.getEditor();
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -269,6 +271,7 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle
|
||||
}
|
||||
if (this._findCountChangeListener === undefined && this._notebookModel) {
|
||||
this._findCountChangeListener = this.notebookInput.notebookFindModel.onFindCountChange(() => this._updateFinderMatchState());
|
||||
this.registerModelChanges();
|
||||
}
|
||||
if (e.isRevealed) {
|
||||
if (this._findState.isRevealed) {
|
||||
@@ -281,14 +284,20 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle
|
||||
this._finder.getDomNode().style.visibility = 'hidden';
|
||||
this._findDecorations.clearDecorations();
|
||||
}
|
||||
} else {
|
||||
if (!this._findState.isRevealed) {
|
||||
this._finder.getDomNode().style.visibility = 'hidden';
|
||||
this._findDecorations.clearDecorations();
|
||||
}
|
||||
}
|
||||
|
||||
if (e.searchString || e.matchCase || e.wholeWord) {
|
||||
this._findDecorations.clearDecorations();
|
||||
// if the search scope changes remove the prev
|
||||
if (this._notebookModel) {
|
||||
if (this._findState.searchString) {
|
||||
let findScope = this._findDecorations.getFindScope();
|
||||
if (this._findState.searchString === this.notebookFindModel.findExpression && findScope !== null && !e.matchCase && !e.wholeWord) {
|
||||
if (this._findState.searchString === this.notebookFindModel.findExpression && findScope !== null && !e.matchCase && !e.wholeWord && !e.searchScope) {
|
||||
if (findScope) {
|
||||
this._updateFinderMatchState();
|
||||
this._findState.changeMatchInfo(
|
||||
@@ -328,6 +337,46 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.searchScope) {
|
||||
await this.notebookInput.notebookFindModel.find(this._findState.searchString, this._findState.matchCase, this._findState.wholeWord, NOTEBOOK_MAX_MATCHES).then(findRange => {
|
||||
this._findDecorations.set(this.notebookFindModel.findMatches, this._currentMatch);
|
||||
this._findState.changeMatchInfo(
|
||||
this.notebookFindModel.getIndexByRange(this._currentMatch),
|
||||
this._findDecorations.getCount(),
|
||||
this._currentMatch
|
||||
);
|
||||
if (this._finder.getDomNode().style.visibility === 'visible') {
|
||||
this._setCurrentFindMatch(this._currentMatch);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private registerModelChanges(): void {
|
||||
let changeEvent: FindReplaceStateChangedEvent = {
|
||||
moveCursor: true,
|
||||
updateHistory: true,
|
||||
searchString: false,
|
||||
replaceString: false,
|
||||
isRevealed: false,
|
||||
isReplaceRevealed: false,
|
||||
isRegex: false,
|
||||
wholeWord: false,
|
||||
matchCase: false,
|
||||
preserveCase: false,
|
||||
searchScope: true,
|
||||
matchesPosition: false,
|
||||
matchesCount: false,
|
||||
currentMatch: false
|
||||
};
|
||||
this._notebookModel.cells.forEach(cell => {
|
||||
this._register(cell.onCellModeChanged((state) => {
|
||||
this._onFindStateChange(changeEvent).catch(onUnexpectedError);
|
||||
}));
|
||||
});
|
||||
this._register(this._notebookModel.contentChanged(e => {
|
||||
this._onFindStateChange(changeEvent).catch(onUnexpectedError);
|
||||
}));
|
||||
}
|
||||
|
||||
public setSelection(range: NotebookRange): void {
|
||||
|
||||
Reference in New Issue
Block a user