Skip to content

Commit

Permalink
Finish splitting out the documentsearch package.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongrout committed Feb 4, 2019
1 parent d33ae81 commit 6a04da9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/csvviewer-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import { InstanceTracker, IThemeManager, Dialog } from '@jupyterlab/apputils';

import { ISearchProviderRegistry } from '@jupyterlab/documentsearch-extension';
import { ISearchProviderRegistry } from '@jupyterlab/documentsearch';

import {
CSVViewer,
Expand Down
2 changes: 2 additions & 0 deletions packages/documentsearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"@jupyterlab/cells": "^0.19.1",
"@jupyterlab/codeeditor": "^0.19.1",
"@jupyterlab/codemirror": "^0.19.1",
"@jupyterlab/docregistry": "^0.19.1",
"@jupyterlab/fileeditor": "^0.19.1",
"@jupyterlab/notebook": "^0.19.2",
"@phosphor/coreutils": "^1.3.0",
"@phosphor/disposable": "^1.1.2",
Expand Down
30 changes: 15 additions & 15 deletions packages/documentsearch/src/providers/codemirrorsearchprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { ISignal, Signal } from '@phosphor/signaling';
import { Widget } from '@phosphor/widgets';

import * as CodeMirror from 'codemirror';
import { IDocumentWidget } from '@jupyterlab/docregistry';
import { FileEditor } from '@jupyterlab/fileeditor';

type MatchMap = { [key: number]: { [key: number]: ISearchMatch } };

Expand All @@ -53,29 +53,29 @@ export class CodeMirrorSearchProvider implements ISearchProvider {
*
* @returns A promise that resolves with a list of all matches
*/
// TODO: Make the searchTarget a normal file editor, and get the codemirror
// out of that. TODO: change the canSearch to be a function from the
// registrar, so that it can interface with the system at registration time.
async startQuery(
query: RegExp,
searchTarget: IDocumentWidget<FileEditor>
searchTarget: Widget
): Promise<ISearchMatch[]> {
// Extract the codemirror object from the editor widget
this._cm = searchTarget.content.editor;
return this._startQuery(query);

if (searchTarget instanceof CodeMirrorEditor) {
this._cm = searchTarget;
} else if (searchTarget instanceof MainAreaWidget) {
} else {
if (!CodeMirrorSearchProvider.canSearchOn(searchTarget)) {
throw new Error('Cannot find Codemirror instance to search');
}

// Extract the codemirror object from the editor widget. Each of these casts
// is justified by the canSearchOn call above.
let target = searchTarget as MainAreaWidget;
let content = target.content as FileEditor;
this._cm = content.editor as CodeMirrorEditor;
return this._startQuery(query);
}

/**
* Initialize the search using a CodeMirrorEditor object.
*/
async startQueryCodeMirror(query: RegExp, searchTarget: CodeMirrorEditor): Promise<ISearchMatch[]> {
async startQueryCodeMirror(
query: RegExp,
searchTarget: CodeMirrorEditor
): Promise<ISearchMatch[]> {
this._cm = searchTarget;
return this._startQuery(query);
}
Expand Down Expand Up @@ -165,7 +165,7 @@ export class CodeMirrorSearchProvider implements ISearchProvider {
static canSearchOn(domain: Widget): boolean {
return (
domain instanceof MainAreaWidget &&
domain.content &&
domain.content instanceof FileEditor &&
domain.content.editor instanceof CodeMirrorEditor
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class NotebookSearchProvider implements ISearchProvider {
cell.inputHidden = false;
}
// chain promises to ensure indexing is sequential
const matchesFromCell = await cmSearchProvider.startQuery(
const matchesFromCell = await cmSearchProvider.startQueryCodeMirror(
query,
cmEditor
);
Expand Down
10 changes: 9 additions & 1 deletion packages/documentsearch/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"outDir": "lib",
"rootDir": "src"
},
"include": ["src/**/*"],
"include": [
"src/**/*"
],
"references": [
{
"path": "../apputils"
Expand All @@ -18,6 +20,12 @@
{
"path": "../codemirror"
},
{
"path": "../docregistry"
},
{
"path": "../fileeditor"
},
{
"path": "../notebook"
}
Expand Down

0 comments on commit 6a04da9

Please sign in to comment.