Maybe the jupyterlab-snippets
extension can serve as an example?
It inserts a new cell in the notebook when the user clicks on a snippet, using NotebookActions.insertBelow
: https://github.com/QuantStack/jupyterlab-snippets/blob/286145d76cc30e5099cab7b1710d26da0171685f/src/index.ts#L121-L125
For your use case, we could imagine that the top cell of the notebook is selected first, and then a new cell is inserted above. Something like this:
const current = notebookTracker.currentWidget;
const notebook = current.content;
notebook.activeCellIndex = 0;
NotebookActions.insertAbove(notebook);