I’m developing an extension that uses a Jupyter notebook to teach students the syntax of a new language.
I need a listener to tell me when a cell’s contents change.
However, the contentChanged listener never seems to trigger.
Am I doing something wrong with how I set this up?
const extension: JupyterFrontEndPlugin<void> = {
id: 'cell-output-logger',
autoStart: true,
requires: [INotebookTracker],
activate: (app: JupyterFrontEnd, notebooks: INotebookTracker) => {
console.log("demo extension loaded");
notebooks.widgetAdded.connect((sender, notebookPanel) => {
console.log('widgetAdded listener triggered. Note, I only expect this once per notebook!!!');
if (!notebooks || !notebooks.currentWidget) { console.log('Notebooks misssing, or lack currentWidget!'); return; }
const cell = notebookPanel.model?.cells.get(0);
console.log(cell);
if (!cell) { console.log('missing cell'); return; }
console.log('cell found, adding the listener')
cell.contentChanged.connect((cell, _) => {
console.log('This cell is listened to');
console.log('cell', cell);
})
})
}
}