-
-
Notifications
You must be signed in to change notification settings - Fork 46
Add extension for document-scoped search #294
Conversation
app: JupyterFrontEnd, | ||
retroShell: IRetroShell, | ||
registry: ISearchProviderRegistry | ||
) => { |
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.
// 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 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 ? 🤷
Thanks @loichuder for starting this!
Right, this is something we often hit over the past couple of months when trying to reuse upstream plugins in alternate JupyterLab distributions. Usually it's fine to duplicate the logic here as temporary solution, and in the meantime we can update the upstream plugin to make is more reusable. In this case this likely means making |
@@ -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) |
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 👍
UI Tests failure looks relevant, as the Edit menu now shows new entries: So we can update the reference snapshots with the ones generated in https://github.com/jupyterlab/retrolab/actions/runs/1506929915 |
Would it be possible that In the meantime, I will keep the duplication as you said. |
Maybe, or this could be hoisted to the |
@jtpio This is now ready for review. Could you explain how to update the screenshots ? Perhaps we could also add this information to CONTRIBUTING if that's something maintainers can do ? |
Yes absolutely. For reference there is some documentation in another repo: https://github.com/jupyterlite/jupyterlite/blob/main/CONTRIBUTING.md#reference-image-captures But we should have something similar here too. Or as an alternative in the JupyterLab contribution docs and we link to it from here: https://github.com/jupyterlab/jupyterlab/blob/master/docs/source/developer/contributing.rst#visual-regression-and-ui-tests |
CI passed 🎉 |
Thanks! This looks good on Binder: search-replace.mp4We can document updating the reference snapshots in a separate PR. |
Yes that was my plan 👍 |
cc @yuvipanda if you have any input on this. I remember you raised some concerns on apps overriding default browser keyboard shortcuts. Here that would be Ctrl / Cmd - F If this comes to much in the way, we could also make it an opt-in instead, for example via a |
Thank you very much for the ping, @jtpio! I really appreciate it! I am also really grateful you working on this, @loichuder! The browser's default Cmd+F is very helpful, as it matches the mental model of 'search for any text I can see' - including all the UI elements. This is very helpful in cases where the user is trying to follow instructions like 'Find item X' - this works even when you just have menu items open (for example): IMO we shouldn't override default browser functionality. The find / replace stuff is pretty cool, but I'd suggest it not be bound to Cmd-F by default. It can be accessed from the menu (as you can in classic notebook right now), and a PageConfig can make that binding if necessary. |
Make sense to me. As I understand, the keyboard shortcut is set via JupyterLab's document-search extension as I reuse one of the plugins of the extension in my implementation. Is this true ? If so, what would be the way to override this ? |
Normally we should be able to disable the shortcut here in retro. For example when testing this PR on Binder: search-replace-keybinding.mp4Which means we could put the following snippet: {
"shortcuts": [
{
"command": "documentsearch:start",
"keys": [
"Accel F"
],
"selector": ".jp-mod-searchable",
"disabled": true
}
]
} In the retro settings by default. Reusing the settings override system added in #289 so we can customize |
Maybe this could be implemented as a separate plugin with its own settings similar to the retrolab/packages/application-extension/src/index.ts Lines 199 to 229 in 49b9ae3
So it could be disabled with |
Also when we implement the override for the For example this could mean using the It would be fine to add that test in a follow-up PR if we want to merge this PR earlier. |
As disabling Ctrl+F is the behaviour we want to have, I think it is better to add it to this PR. I just need to make the override work 😄 |
c9b9526
to
4aed598
Compare
Sorry it took me a while to find the courage to navigate once again in the treacherous plugin sea. I added a plugin to disable the shortcut: 4aed598. Not sure if that is the way you intended it @jtpio so don't hesitate to direct me towards another solution. I will work on the UI test, next. Funfact: While testing, I noticed that the Ctrl+F event is already caught for text files like MD, making a custom search bar appear: This comes not from the So even by disabling the |
Thanks @loichuder. I was more thinking about using the declarative way and override the shortcut in the schema file with
Probably this one would be fine to keep as is yes, especially since classic behaves the same. |
FYI @loichuder I pushed the following commit to switch to the declarative approach: 55915e6 And rebased to grab the changes from #309. Will follow-up with the snapshots update if needed. |
Looks like this is actually picked up by JupyterLab too, which means that the shortcut is now disabled in JupyterLab too: I wouldn't have expected that |
This is now tracked in jupyterlab/jupyterlab#11754. Based on these observations, the least surprising for the end user would then be to keep the programmatic shortcut override added in 38a6166. So it doesn't have any side-effect in JupyterLab. I'll update this PR to revert the last two commits, so we can get it out in the next release and revisit later depending on the status of jupyterlab/jupyterlab#11754. |
Folks can use the Advanced Settings editor to re-enable the shortcut if they would like to (opt-in): enable-crtl-f.mp4 |
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.
Thanks!
Thanks for following that up and ironing out the last wrinkles 🙂 👍 |
@loichuder thank you for working on this! FYI this change was released in |
Fix #181
Well, that wasn't as easy as I first thought 😅
I could not reuse
@jupyterlab/documentsearch-extension
plugin directly as it relies onILabShell
to find the current searchable widget. I therefore rewrote the plugin for retrolab in a new@retrolab/documentsearch-extension
to account for retrolab's differences.I still have a small issue on RetroLab's landing page where
Ctrl+F
is caught when the focus is on theFiles
tab when it should not. This is perhaps related to the way I handledcurrentWidget
in the new plugin.EDIT: Now fixed !
Anyway, before going further, I wanted to draft this first functional implementation to know if I was going the right way. Any comments/feedback are welcomed.