Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove notion of default search providers #6301

Merged
merged 1 commit into from May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/documentsearch-extension/src/index.ts
Expand Up @@ -12,7 +12,9 @@ import { ICommandPalette } from '@jupyterlab/apputils';
import {
ISearchProviderRegistry,
SearchInstance,
SearchProviderRegistry
SearchProviderRegistry,
CodeMirrorSearchProvider,
NotebookSearchProvider
} from '@jupyterlab/documentsearch';

import { IMainMenu } from '@jupyterlab/mainmenu';
Expand Down Expand Up @@ -79,8 +81,10 @@ const extension: JupyterFrontEndPlugin<ISearchProviderRegistry> = {
) => {
// Create registry, retrieve all default providers
const registry: SearchProviderRegistry = new SearchProviderRegistry();
// TODO: Should register the default providers, with an application-specific
// enabler.

// Register default implementations of the Notebook and CodeMirror search providers
registry.register('jp-notebookSearchProvider', NotebookSearchProvider);
registry.register('jp-codeMirrorSearchProvider', CodeMirrorSearchProvider);

const activeSearches = new Map<string, SearchInstance>();

Expand Down
35 changes: 4 additions & 31 deletions packages/documentsearch/src/searchproviderregistry.ts
@@ -1,8 +1,6 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { ISearchProvider, ISearchProviderConstructor } from './interfaces';
import { CodeMirrorSearchProvider } from './providers/codemirrorsearchprovider';
import { NotebookSearchProvider } from './providers/notebooksearchprovider';

import { Token } from '@phosphor/coreutils';
import { Widget } from '@phosphor/widgets';
Expand Down Expand Up @@ -43,28 +41,17 @@ export interface ISearchProviderRegistry {
}

export class SearchProviderRegistry implements ISearchProviderRegistry {
constructor() {
this._registerDefaultProviders(
'jl-defaultNotebookSearchProvider',
NotebookSearchProvider
);
this._registerDefaultProviders(
'jl-defaultCodeMirrorSearchProvider',
CodeMirrorSearchProvider
);
}

/**
* Add a provider to the registry.
*
* @param key - The provider key.
* @returns A disposable delegate that, when disposed, deregisters the given search provider
*/
register(key: string, provider: ISearchProviderConstructor): IDisposable {
this._customProviders.set(key, provider);
this._providerMap.set(key, provider);
this._changed.emit();
return new DisposableDelegate(() => {
this._customProviders.delete(key);
this._providerMap.delete(key);
this._changed.emit();
});
}
Expand All @@ -76,10 +63,7 @@ export class SearchProviderRegistry implements ISearchProviderRegistry {
* @returns the search provider, or undefined if none exists.
*/
getProviderForWidget(widget: Widget): ISearchProvider | undefined {
return (
this._findMatchingProvider(this._customProviders, widget) ||
this._findMatchingProvider(this._defaultProviders, widget)
);
return this._findMatchingProvider(this._providerMap, widget);
}

/**
Expand All @@ -90,13 +74,6 @@ export class SearchProviderRegistry implements ISearchProviderRegistry {
return this._changed;
}

private _registerDefaultProviders(
key: string,
provider: ISearchProviderConstructor
): void {
this._defaultProviders.set(key, provider);
}

private _findMatchingProvider(
providerMap: Private.ProviderMap,
widget: Widget
Expand All @@ -112,11 +89,7 @@ export class SearchProviderRegistry implements ISearchProviderRegistry {
}

private _changed = new Signal<this, void>(this);
private _defaultProviders: Private.ProviderMap = new Map<
string,
ISearchProviderConstructor
>();
private _customProviders: Private.ProviderMap = new Map<
private _providerMap: Private.ProviderMap = new Map<
string,
ISearchProviderConstructor
>();
Expand Down