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:
Maddy
2020-03-25 22:47:06 -07:00
committed by GitHub
parent 4241ca523e
commit 685e0ccf7e
12 changed files with 177 additions and 28 deletions

View File

@@ -833,4 +833,39 @@ suite('Cell Model', function (): void {
assert.strictEqual(actualMsg, testMsg);
});
});
test('Should emit event on markdown cell edit', async function (): Promise<void> {
let notebookModel = new NotebookModelStub({
name: '',
version: '',
mimetype: ''
});
let contents: nb.ICellContents = {
cell_type: CellTypes.Markdown,
source: ''
};
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
assert(!model.isEditMode);
let createCellModePromise = () => {
return new Promise((resolve, reject) => {
setTimeout((error) => reject(error), 2000);
model.onCellModeChanged(isEditMode => {
resolve(isEditMode);
});
});
};
assert(!model.isEditMode);
let cellModePromise = createCellModePromise();
model.isEditMode = true;
let isEditMode = await cellModePromise;
assert(isEditMode);
cellModePromise = createCellModePromise();
model.isEditMode = false;
isEditMode = await cellModePromise;
assert(!isEditMode);
});
});

View File

@@ -323,6 +323,41 @@ suite('Notebook Find Model', function (): void {
assert.equal(notebookFindModel.findMatches.length, 0, 'Find failed to apply match whole word for //');
});
test('Should find results in the code cell on markdown edit', async function (): Promise<void> {
let markdownContent: nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Markdown,
source: ['SOP067 - INTERNAL - Install azdata CLI - release candidate', '==========================================================', 'Steps', '-----', '### Parameters'],
metadata: { language: 'python' },
execution_count: 1
}],
metadata: {
kernelspec: {
name: 'mssql',
language: 'sql'
}
},
nbformat: 4,
nbformat_minor: 5
};
await initNotebookModel(markdownContent);
// Need to set rendered text content for 1st cell
setRenderedTextContent(0);
let notebookFindModel = new NotebookFindModel(model);
await notebookFindModel.find('SOP', false, false, max_find_count);
assert.equal(notebookFindModel.findMatches.length, 1, 'Find failed on markdown');
// fire the edit mode on cell
model.cells[0].isEditMode = true;
notebookFindModel = new NotebookFindModel(model);
await notebookFindModel.find('SOP', false, false, max_find_count);
assert.equal(notebookFindModel.findMatches.length, 2, 'Find failed on markdown edit');
});
async function initNotebookModel(contents: nb.INotebookContents): Promise<void> {
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);

View File

@@ -123,7 +123,6 @@ export class NotebookModelStub implements INotebookModel {
}
export class NotebookFindModelStub implements INotebookFindModel {
getFindCount(): number {
throw new Error('Method not implemented.');
}
@@ -158,6 +157,9 @@ export class NotebookFindModelStub implements INotebookFindModel {
findMatches: NotebookFindMatch[];
findExpression: string;
onFindCountChange: vsEvent.Event<number>;
getIndexByRange(range: NotebookRange): number {
throw new Error('Method not implemented.');
}
}
export class NotebookManagerStub implements INotebookManager {