Просмотр исходного кода

remove notion of default search providers

Andrew Schlaepfer 6 лет назад
Родитель
Сommit
18d8c1411a

+ 7 - 3
packages/documentsearch-extension/src/index.ts

@@ -12,7 +12,9 @@ import { ICommandPalette } from '@jupyterlab/apputils';
 import {
   ISearchProviderRegistry,
   SearchInstance,
-  SearchProviderRegistry
+  SearchProviderRegistry,
+  CodeMirrorSearchProvider,
+  NotebookSearchProvider
 } from '@jupyterlab/documentsearch';
 
 import { IMainMenu } from '@jupyterlab/mainmenu';
@@ -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>();
 

+ 4 - 31
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';
@@ -43,17 +41,6 @@ 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.
    *
@@ -61,10 +48,10 @@ export class SearchProviderRegistry implements ISearchProviderRegistry {
    * @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();
     });
   }
@@ -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);
   }
 
   /**
@@ -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
@@ -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
   >();