This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from loichuder/doc-search
Add extension for document-scoped search
- Loading branch information
Showing
14 changed files
with
686 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) => { | ||
// 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) => { | ||
if (retroShell.currentWidget) { | ||
transformWidgetSearchability(retroShell.currentWidget); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Export the plugins as default. | ||
*/ | ||
const plugins: JupyterFrontEndPlugin<any>[] = [ | ||
disableShortcut, | ||
retroShellWidgetListener | ||
]; | ||
|
||
export default plugins; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import url('./base.css'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './base.css'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfigbase", | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
Binary file modified
BIN
+3.79 KB
(110%)
ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.77 KB
(110%)
ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.