marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
6.79k stars 239 forks source link

minimize active cell movement during re-evaluation #1749

Closed ggggggggg closed 2 months ago

ggggggggg commented 3 months ago

Description

I'm working on a notebook that makes many plots using matplotlib (which works great btw! Thanks!). When I redfine a cell that causes many plots to be re-evaluated, I find that I have to just step back and wait for all the re-evaluation to finish before I can make any more changes to that or any other cells. This is because every time a new plot is rendered, the vertical position of cells within the browser changes.

Suggested solution

My features request is to minimize the extent to which the active cell (the one I'm typing in) visually moves during re-evaluation. I suspect that a rule like "stuff rendered off screen can't move the active cell" may be a good heuristic, but I don't have strong feeling about the details.

Alternative

No response

Additional context

This linked notebook reproduces the issue. To try it, marimo edit the notebook, then find the cell that defines n=2 and redefine n. Then try to redefine n again quickly with a more complex expression.

ggggggggg commented 3 months ago

I have a fairly long notebook, and when I navigate to the bottom of the notebook, then click the plus button for a new cell below the last cell, it scrolls up about 80% of the way to the top of the notebook. I would prefer it stay looking at the new cell I just made.

This notebook displays the same behavior. To reproduce scroll to the bottom, press the plus to make a new cell below the last cell.

mscolnick commented 3 months ago

@ggggggggg - i noticed that too - i fixed that here: https://github.com/marimo-team/marimo/pull/1782

ggggggggg commented 2 months ago

It seems like when a cell ending with mo.mpl.interactive(plt.gcf()) finishes rendering, it still moves focus to that cell. So I basically lose my place in the notebook every time I run a cell that causes re-plotting.