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
Add extension for document-scoped search #294
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
656c09f
Add extension for document-scoped search
loichuder 5f24af6
Updated snapshots for UI tests
loichuder 38a6166
Add a plugin to disable document search shortcut
loichuder 55915e6
Switch to declarative keyboard shortcuts
jtpio 37b0c2e
Update reference snapshots
jtpio 7c0b058
Switch back to shortcut override plugin
jtpio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contrary to 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.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 👍