Skip to content

Commit

Permalink
Fix search coming back in notebook and editor
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Nov 27, 2023
1 parent 4747a9c commit 17b52c5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/documentsearch-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ const extension: JupyterFrontEndPlugin<ISearchProviderRegistry> = {
if (!currentWidget) {
return;
}

searchViews.get(currentWidget.id)?.close();
}
});
Expand Down
16 changes: 14 additions & 2 deletions packages/documentsearch/src/searchmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class SearchDocumentModel
}
}

searchProvider.stateChanged.connect(this.refresh, this);
searchProvider.stateChanged.connect(this._onProviderStateChanged, this);

this._searchDebouncer = new Debouncer(() => {
this._updateSearch().catch(reason => {
Expand Down Expand Up @@ -248,7 +248,10 @@ export class SearchDocumentModel
});
}

this.searchProvider.stateChanged.disconnect(this.refresh, this);
this.searchProvider.stateChanged.disconnect(
this._onProviderStateChanged,
this
);

this._searchDebouncer.dispose();
super.dispose();
Expand All @@ -258,6 +261,7 @@ export class SearchDocumentModel
* End the query.
*/
async endQuery(): Promise<void> {
this._searchActive = false;
await this.searchProvider.endQuery();
this.stateChanged.emit();
}
Expand Down Expand Up @@ -351,6 +355,7 @@ export class SearchDocumentModel
)
: null;
if (query) {
this._searchActive = true;
await this.searchProvider.startQuery(query, this._filters);
// Emit state change as the index needs to be updated
this.stateChanged.emit();
Expand All @@ -365,13 +370,20 @@ export class SearchDocumentModel
}
}

private _onProviderStateChanged() {
if (this._searchActive) {
this.refresh();
}
}

private _caseSensitive = false;
private _disposed = new Signal<this, void>(this);
private _parsingError = '';
private _preserveCase = false;
private _initialQuery = '';
private _filters: IFilters = {};
private _replaceText: string = '';
private _searchActive = false;
private _searchDebouncer: Debouncer;
private _searchExpression = '';
private _useRegex = false;
Expand Down
1 change: 1 addition & 0 deletions packages/fileeditor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@jupyter/ydoc": "^1.1.1",
"@jupyterlab/apputils": "^4.2.0-alpha.3",
"@jupyterlab/codeeditor": "^4.1.0-alpha.3",
"@jupyterlab/codemirror": "^4.1.0-alpha.3",
Expand Down
27 changes: 27 additions & 0 deletions packages/fileeditor/src/searchprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { ITranslator } from '@jupyterlab/translation';
import { Widget } from '@lumino/widgets';
import { FileEditor } from './widget';
import { ISharedText, SourceChange } from '@jupyter/ydoc';

/**
* Helper type
Expand Down Expand Up @@ -64,6 +65,7 @@ export class FileEditorSearchProvider
query: RegExp,
filters: IFilters | undefined
): Promise<void> {
this._searchActive = true;
await super.startQuery(query, filters);
await this.highlightNext(true, {
from: 'selection-start',
Expand All @@ -72,6 +74,29 @@ export class FileEditorSearchProvider
});
}

/**
* Stop the search and clean any UI elements.
*/
async endQuery(): Promise<void> {
this._searchActive = false;
await super.endQuery();
}

/**
* Callback on source change
*
* @param emitter Source of the change
* @param changes Source change
*/
protected async onSharedModelChanged(
emitter: ISharedText,
changes: SourceChange
): Promise<void> {
if (this._searchActive) {
super.onSharedModelChanged(emitter, changes);

Check failure on line 96 in packages/fileeditor/src/searchprovider.ts

View workflow job for this annotation

GitHub Actions / Linux (lint, 3.11)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
}

/**
* Instantiate a search provider for the widget.
*
Expand Down Expand Up @@ -116,4 +141,6 @@ export class FileEditorSearchProvider
);
return selection;
}

private _searchActive = false;
}
7 changes: 6 additions & 1 deletion packages/notebook/src/searchprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
return;
}
await this.endQuery();
this._searchActive = true;
let cells = this.widget.content.widgets;

this._query = query;
Expand Down Expand Up @@ -426,6 +427,7 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
})
);

this._searchActive = false;
this._searchProviders.length = 0;
this._currentProviderIndex = null;
}
Expand Down Expand Up @@ -552,7 +554,9 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
this.widget.content.isSelectedOrActive(cell)
)
.then(() => {
void cellSearchProvider.startQuery(this._query, this._filters);
if (this._searchActive) {
void cellSearchProvider.startQuery(this._query, this._filters);
}
});
}

Expand Down Expand Up @@ -914,4 +918,5 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
> | null = null;
private _selectionSearchMode: 'cells' | 'text' = 'cells';
private _selectionLock: boolean = false;
private _searchActive: boolean = false;
}
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3459,6 +3459,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyterlab/fileeditor@workspace:packages/fileeditor"
dependencies:
"@jupyter/ydoc": ^1.1.1
"@jupyterlab/apputils": ^4.2.0-alpha.3
"@jupyterlab/codeeditor": ^4.1.0-alpha.3
"@jupyterlab/codemirror": ^4.1.0-alpha.3
Expand Down

0 comments on commit 17b52c5

Please sign in to comment.