-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notebook: Find in both text model and output #140098
Comments
Most browsers support basic text search but it comes with quite some weaknesses: no UI customization, no regular expression support, no support for Replace, and most importantly, not working well if the view is virtualized (as it can only search for what’s in the DOM tree). This is one of the reasons why we build our own find widget for the text editor and notebook. It searches on the text model of the resources, instead of rendered view / DOM tree. The search operations are synchronous and most of the time performant. With that being said, searching on text model has it limitation. It doesn’t work for outputs in notebook documents as outputs can be stored in any format (e.g., binary), and since they are rendered by custom renderers, what’s stored in One simple example is markdown outputs. Say we have a markdown output The notebook editor in the core is a virtualized list as we don’t want to render all cell inputs (rendering monaco editors are costly). To allow users to have a seamless search experience, we would need to search on both text models and rendered outputs:
There is no simple browser API for searching string on DOM so we would explore what we can do to implement something close to the browser’s find experience, which would include:
Search on the DOMThe browser find widget is not accessible to JavaScript applications. The only API available to us is let found = true;
const ranges = [];
while (found) {
found = window.find(query,
/* caseSensitive*/ false,
/* backwards*/ false,
/* wrapAround*/ false,
/* wholeWord */ false,
/* searchInFrames*/ false,
false
);
if (found) {
ranges.push(document.getSelection().getRangeAt(0).cloneRange())
}
} Since The other limitation of Even though Highlight matchesOnce we get the ranges of the matches in the DOM tree, the next step is highlighting them based on users’ theme colors. We have a few options but none of them is mature or performant enough:
AlternativesBased on all the investigations,
|
Had offline discussions with @deepak1556 @rzhao271 @mjbvz on Chromium/Electron APIs for find and highlight text and their JavaScript alternatives and here are what we found:
With solutions proposed above, we would currently take the JS approach and continue UX experiments, and polish the implementation with more native API coming in. |
Good news is the Highlight API is already available in Chromium behind a flag and we can enable it for our upcoming Electron build. We would use the JS version for now and use the Highlight API once it's available. From our Edge friends, the Highlight API is likely to release around April. Since we support searching in both the cell source code, markup preview and cell outputs, we would introduce a new filter in the notebook find widget, next to Case Sensitivity, Match Case and Regex. |
tried it, looking good, were able to search through outputs and inputs. |
We will explore how to support searching text in both text model and outputs. The major challenge is that the notebook is a virtualized list view and we need to search the DOM content.
The text was updated successfully, but these errors were encountered: