feat(toolbar): insert cells after focused cell#658
Conversation
When clicking +Code or +Markdown in the toolbar, new cells now insert after the currently focused cell instead of at the top. If no cell is focused, the new cell is inserted after the last cell (or at the top if the notebook is empty).
There was a problem hiding this comment.
Pull request overview
This PR modifies the notebook toolbar's +Code and +Markdown buttons to insert new cells contextually — after the currently focused cell — rather than always prepending at the top. When no cell is focused, cells are appended after the last existing cell (or at position 0 for empty notebooks). The addCell function in useAutomergeNotebook already accepted an optional afterCellId parameter, so the changes are limited to threading the focused cell ID and last cell ID to the toolbar component.
Changes:
- Extended
NotebookToolbarPropswithfocusedCellIdandlastCellIdprops, and updatedonAddCellsignature to accept an optionalafterCellId. - Updated toolbar button click handlers to pass
focusedCellId ?? lastCellIdas the insertion target. - Threaded the new props from
AppContenttoNotebookToolbar, computinglastCellIdfrom the cells array.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
apps/notebook/src/components/NotebookToolbar.tsx |
Added focusedCellId and lastCellId props; updated +Code and +Markdown button handlers to pass the insertion position. |
apps/notebook/src/App.tsx |
Passes focusedCellId and computed lastCellId to the NotebookToolbar component. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
The toolbar's +Code and +Markdown buttons now insert new cells after the currently focused cell, instead of always prepending at the top. If no cell is focused, the new cell is inserted after the last cell (or at the top if the notebook is empty).
This matches the intuitive behavior of the inline "Add Cell" buttons that appear between cells.
Verification
PR submitted by @rgbkrk's agent, Quill