Skip to content

frontend/jupyter: add cell-type switches to the button menu of a cell #8473

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

Merged
merged 3 commits into from
Jul 30, 2025

Conversation

haraldschilly
Copy link
Contributor

@haraldschilly haraldschilly commented Jul 29, 2025

This is how it looks (including some reorg), but needs more work.

The only usability issue is, if you switch away from a code type, that cell menu is gone as well. Then you're stuck in markdown and the menu where you did the change can't be reached. So, the extra work here is to make that menu available for all cell types, and only show "run" and so on if it makes sense.

What I did is to remove the "Edit" button from rendering it in the "cell input", down to render it in the "cell-buttonbar". With that, everything is in one place. Bonus: it is trivial to enable the "Format" button for markdown as well, although it is a bit strange if the cell isn't in edit mode and edited as markdown. So, I left it disabled as before.

Screenshot from 2025-07-29 12-25-20

Ok, and here is with the additional changes for markdown and raw cells. The "Edit" button is actually a toggle now. The menu now allows undo/redo, moving, cutting, etc. for markdown as well.

Screenshot from 2025-07-29 16-12-16

@haraldschilly haraldschilly force-pushed the jupyter-celltype-cellmenu-8472 branch from 55e07ae to a5fb1d2 Compare July 29, 2025 12:19
@williamstein
Copy link
Contributor

only show "run" and so on if it makes sense.

Running a markdown cell makes sense -- it means changing it from edit mode to non-edit mode.

…, to have everything in one place. With that, the cell menu appears on markdown cells as well
@haraldschilly haraldschilly force-pushed the jupyter-celltype-cellmenu-8472 branch from c8cf870 to 3e0373d Compare July 29, 2025 14:17
@haraldschilly haraldschilly marked this pull request as ready for review July 29, 2025 14:27
@haraldschilly haraldschilly force-pushed the jupyter-celltype-cellmenu-8472 branch from 5c5b04a to 51b2432 Compare July 29, 2025 17:48
@haraldschilly
Copy link
Contributor Author

But what's being run? Well, in any case, I added the run button. I had to experiment a bit, because the shift evaluation, the menu run button, and the cell run button are slightly different. I got it working, though. The key was to change the cell buttonbar run button's actions?.run_cell(id) to frameActions.current?.run_cell(id)

@williamstein
Copy link
Contributor

But what's being run?

The definition of "run" is "compile the markdown source into a visible rendered view". That said, this would be super annoying if it happened for all viewers at once, so only the particular frame that you're viewing has its mode changed from edit to view. That's why it's frameActions.current?.run_cell(id) since actions?.run_cell(id) has no knowledge of the particular frame.

@@ -421,8 +422,7 @@ export class NotebookFrameActions {
undefined,
false,
);
let md_edit_ids = this.store.get("md_edit_ids");
if (md_edit_ids == null) md_edit_ids = Set();
const md_edit_ids = this.store.get("md_edit_ids", Set());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change you just made is NOT equivalent and it pretty dangerous. If 'md_edit_ids' is actually set to undefined or to null in the store, then this.store.get("md_edit_ids", Set()); would be undefined or null, NOT Set(). It's much, much safer to do:

const md_edit_ids = this.store.get("md_edit_ids") ?? Set()

It's also more efficient since above doesn't evaluate Set() unless needed, whereas this.store.get("md_edit_ids", Set()); always does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, the function that implement this.store.get(...) could also be changed to basically do the ?? thing. That said, I generally think ?? is just better, and we shouldn't write new code using that second input to get. I probably did so also in the last week, but I'm going to stop.

@@ -487,7 +487,7 @@ export class NotebookFrameActions {
const cell = this.get_cell_by_id(id);
if (cell == null) return;

if (cell.getIn(["metadata", "editable"]) === false) {
if (!this.jupyter_actions.store.is_cell_editable(id)) {
// TODO: NEVER ever silently fail!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to delete my comment "// TODO: NEVER ever silently fail!" -- I've learned people greatly prefer silent failures to errors they don't understand. At most, log something to the console...

@williamstein williamstein merged commit 5abdd6c into master Jul 30, 2025
4 checks passed
@williamstein
Copy link
Contributor

I had a nitpick comment or two, but no actual bug, so I merged this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants