Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Add extension for document-scoped search #294

Merged
merged 6 commits into from
Dec 28, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ async function main() {
require('@retrolab/application-extension'),
require('@retrolab/console-extension'),
require('@retrolab/docmanager-extension'),
require('@retrolab/documentsearch-extension'),
require('@retrolab/help-extension'),
require('@retrolab/notebook-extension'),
// to handle opening new tabs after creating a new terminal
Expand Down Expand Up @@ -123,6 +124,9 @@ async function main() {
].includes(id)
),
require('@jupyterlab/docprovider-extension'),
require('@jupyterlab/documentsearch-extension').default.filter(({ id }) =>
['@jupyterlab/documentsearch:plugin'].includes(id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good that we are at least able to reuse this plugin 👍

),
require('@jupyterlab/filebrowser-extension').default.filter(({ id }) =>
['@jupyterlab/filebrowser-extension:factory'].includes(id)
),
Expand Down
8 changes: 8 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"@jupyterlab/docmanager-extension": "~3.2.0",
"@jupyterlab/docprovider": "~3.2.0",
"@jupyterlab/docprovider-extension": "~3.2.0",
"@jupyterlab/documentsearch": "~3.2.4",
"@jupyterlab/documentsearch-extension": "~3.2.4",
"@jupyterlab/filebrowser": "~3.2.0",
"@jupyterlab/filebrowser-extension": "~3.2.0",
"@jupyterlab/fileeditor": "~3.2.0",
Expand Down Expand Up @@ -78,6 +80,7 @@
"@retrolab/application-extension": "~0.3.13",
"@retrolab/console-extension": "~0.3.13",
"@retrolab/docmanager-extension": "~0.3.13",
"@retrolab/documentsearch-extension": "~0.3.13",
"@retrolab/help-extension": "~0.3.13",
"@retrolab/notebook-extension": "~0.3.13",
"@retrolab/terminal-extension": "~0.3.13",
Expand All @@ -97,6 +100,7 @@
"@jupyterlab/coreutils": "~5.2.0",
"@jupyterlab/docmanager-extension": "^3.2.0",
"@jupyterlab/docprovider-extension": "^3.2.0",
"@jupyterlab/documentsearch-extension": "^3.2.0",
"@jupyterlab/filebrowser-extension": "^3.2.0",
"@jupyterlab/fileeditor-extension": "^3.2.0",
"@jupyterlab/hub-extension": "^3.2.0",
Expand All @@ -119,6 +123,7 @@
"@retrolab/application-extension": "^0.3.13",
"@retrolab/console-extension": "^0.3.13",
"@retrolab/docmanager-extension": "^0.3.13",
"@retrolab/documentsearch-extension": "^0.3.13",
"@retrolab/help-extension": "^0.3.13",
"@retrolab/notebook-extension": "^0.3.13",
"@retrolab/terminal-extension": "^0.3.13",
Expand Down Expand Up @@ -153,6 +158,7 @@
"@retrolab/application-extension",
"@retrolab/console-extension",
"@retrolab/docmanager-extension",
"@retrolab/documentsearch-extension",
"@retrolab/help-extension",
"@retrolab/notebook-extension",
"@retrolab/terminal-extension",
Expand All @@ -163,6 +169,7 @@
"@jupyterlab/completer-extension",
"@jupyterlab/console-extension",
"@jupyterlab/docmanager-extension",
"@jupyterlab/documentsearch-extension",
"@jupyterlab/filebrowser-extension",
"@jupyterlab/fileeditor-extension",
"@jupyterlab/hub-extension",
Expand All @@ -188,6 +195,7 @@
"@jupyterlab/coreutils",
"@jupyterlab/docmanager",
"@jupyterlab/docprovider",
"@jupyterlab/documentsearch",
"@jupyterlab/filebrowser",
"@jupyterlab/fileeditor",
"@jupyterlab/mainmenu",
Expand Down
1 change: 1 addition & 0 deletions packages/_metapackage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@retrolab/application-extension": "file:../application-extension",
"@retrolab/console-extension": "file:../console-extension",
"@retrolab/docmanager-extension": "file:../docmanager-extension",
"@retrolab/documentsearch-extension": "file:../documentsearch-extension",
"@retrolab/help-extension": "file:../help-extension",
"@retrolab/lab-extension": "file:../lab-extension",
"@retrolab/notebook-extension": "file:../notebook-extension",
Expand Down
1 change: 1 addition & 0 deletions packages/_metapackage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@retrolab/application';
import '@retrolab/application-extension';
import '@retrolab/console-extension';
import '@retrolab/docmanager-extension';
import '@retrolab/documentsearch-extension';
import '@retrolab/help-extension';
import '@retrolab/lab-extension';
import '@retrolab/notebook-extension';
Expand Down
1 change: 1 addition & 0 deletions packages/_metapackage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{ "path": "../application-extension" },
{ "path": "../console-extension" },
{ "path": "../docmanager-extension" },
{ "path": "../documentsearch-extension" },
{ "path": "../help-extension" },
{ "path": "../lab-extension" },
{ "path": "../notebook-extension" },
Expand Down
58 changes: 58 additions & 0 deletions packages/documentsearch-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@retrolab/documentsearch-extension",
"version": "0.3.13",
"description": "RetroLab - Document Search Extension",
"homepage": "https://github.com/jupyterlab/retrolab",
"bugs": {
"url": "https://github.com/jupyterlab/retrolab/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/jupyterlab/retrolab.git"
},
"license": "BSD-3-Clause",
"author": "Project Jupyter",
"sideEffects": [
"style/**/*.css",
"style/index.js"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"style": "style/index.css",
"directories": {
"lib": "lib/"
},
"files": [
"lib/*.d.ts",
"lib/*.js.map",
"lib/*.js",
"schema/*.json",
"style/**/*.css",
"style/index.js"
],
"scripts": {
"build": "tsc -b",
"build:prod": "tsc -b",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
"docs": "typedoc src",
"prepublishOnly": "npm run build",
"watch": "tsc -b --watch"
},
"dependencies": {
"@jupyterlab/application": "^3.2.0",
"@retrolab/application": "^0.3.13",
"@jupyterlab/documentsearch": "^3.2.0",
"@lumino/widgets": "^1.23.0"
},
"devDependencies": {
"rimraf": "~3.0.0",
"typescript": "~4.1.3"
},
"publishConfig": {
"access": "public"
},
"jupyterlab": {
"extension": true
},
"styleModule": "style/index.js"
}
92 changes: 92 additions & 0 deletions packages/documentsearch-extension/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

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

import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { Widget } from '@lumino/widgets';

import { IRetroShell } from '@retrolab/application';

const SEARCHABLE_CLASS = 'jp-mod-searchable';

/**
* A plugin to programmatically disable the Crtl-F shortcut in RetroLab
* See https://github.com/jupyterlab/retrolab/pull/294 and
* https://github.com/jupyterlab/jupyterlab/issues/11754 for more context.
*/
const disableShortcut: JupyterFrontEndPlugin<void> = {
id: '@retrolab/documentsearch-extension:disableShortcut',
requires: [ISettingRegistry],
autoStart: true,
activate: async (app: JupyterFrontEnd, registry: ISettingRegistry) => {
const docSearchShortcut = registry.plugins[
'@jupyterlab/documentsearch-extension:plugin'
]?.schema['jupyter.lab.shortcuts']?.find(
shortcut => shortcut.command === 'documentsearch:start'
);

if (docSearchShortcut) {
docSearchShortcut.disabled = true;
docSearchShortcut.keys = [];
}
}
};

/**
* A plugin to add document search functionalities.
*/
const retroShellWidgetListener: JupyterFrontEndPlugin<void> = {
id: '@retrolab/documentsearch-extension:retroShellWidgetListener',
requires: [IRetroShell, ISearchProviderRegistry],
autoStart: true,
activate: (
app: JupyterFrontEnd,
retroShell: IRetroShell,
registry: ISearchProviderRegistry
) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// If a given widget is searchable, apply the searchable class.
// If it's not searchable, remove the class.
const transformWidgetSearchability = (widget: Widget | null) => {
if (!widget) {
return;
}
const providerForWidget = registry.getProviderForWidget(widget);
if (providerForWidget) {
widget.addClass(SEARCHABLE_CLASS);
}
if (!providerForWidget) {
widget.removeClass(SEARCHABLE_CLASS);
}
};

// Update searchability of the active widget when the registry
// changes, in case a provider for the current widget was added
// or removed
registry.changed.connect(() =>
transformWidgetSearchability(retroShell.currentWidget)
);

// Apply the searchable class only to the active widget if it is actually
// searchable. Remove the searchable class from a widget when it's
// no longer active.
retroShell.currentChanged.connect((_, args) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contrary to labShell.activeChanged, retroShell.currentChanged does not provide args containing the old and new widgets. I could not reproduce the behaviour in https://github.com/jupyterlab/jupyterlab/blob/a8dff39a1a2be850a80861e05145e763079b8794/packages/documentsearch-extension/src/index.ts#L64 where the class is removed for inactive widgets.

But, given that Retrolab only has one widget by browser tab, I think this is fine ? 🤷

if (retroShell.currentWidget) {
transformWidgetSearchability(retroShell.currentWidget);
}
});
}
};

/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
disableShortcut,
retroShellWidgetListener
];

export default plugins;
Empty file.
1 change: 1 addition & 0 deletions packages/documentsearch-extension/style/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('./base.css');
1 change: 1 addition & 0 deletions packages/documentsearch-extension/style/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './base.css';
8 changes: 8 additions & 0 deletions packages/documentsearch-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": ["src/**/*"]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading