Hi!
I am working on a JupyterLab extension that mimics the bookmarks
extension in VSCode, but I am running into a problem / point of confusion. Hopefully, somewhere can point me in the right direction!
Specifically, I want to apply some simple formatting to bookmarked cells, which is easy to achieve through a “bookmarked” class and some CSS. The challenge I am running into is that I want my bookmarks to be persistent, so I keep track of whether a cell is bookmarked or not through a custom metadata flag.
As far as I can tell, there is no way to apply styling to a cell based on its metadata. Based on a Stackoverflow thread I found (link), it appears that I need to reapply the bookmarked class to every cell with the metadata flag whenever a notebook is loaded. Is that right?
If so, then the question becomes, how do I listen for a new notebook to be opened and fire my logic to apply the classes? The SO post includes a potential solution, but to avoid unnecessary overhead, I’d ideally only like to fire this logic once every time a notebook is opened.
I have searched through existing extensions, the JupyterLab source code, and the documentation, and I am fairly certain that I will need to use currentChanged
(i.e., some form of signal interaction). My problem, however, is that my code will always try to link itself to the signal before the notebookTracker/shell is initialized, causing it to error out.
E.g., if I include this in my code (where labShell: ILabShell
)
if (labShell) {
labShell.currentChanged.connect((_, update) => {
console.log('Changed');
});
} else {
console.log('labShell is null');
}
It will always yield the “LabShell is null” condition because it tries to reach labShell before it is initialized.
Clearly, I am lacking some understanding here, so a pointer would be much appreciated.
Thanks!!