Skip to content

Commit

Permalink
Merge pull request #6301 from aschlaep/no-default-searchproviders
Browse files Browse the repository at this point in the history
Remove notion of default search providers
  • Loading branch information
blink1073 committed May 2, 2019
2 parents 0e1e34e + 18d8c14 commit 84d6eca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
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

0 comments on commit 84d6eca

Please sign in to comment.