Skip to content
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

Put the cursor at the merge point after merging two notebook cells #9671

Open
mgeier opened this issue Jan 25, 2021 · 5 comments
Open

Put the cursor at the merge point after merging two notebook cells #9671

mgeier opened this issue Jan 25, 2021 · 5 comments
Milestone

Comments

@mgeier
Copy link
Contributor

mgeier commented Jan 25, 2021

Each cell seems to have a stored cursor position, which is restored whenever the cell is switched into "edit mode" by pressing the "Enter" key.

Problem

When merging two cells, the cursor position is reset to the beginning of the cell.

Proposed Solution

I think it would make more sense (if technically feasible), to set the cursor position to the merge point.

The cursor is normally at the "last edited" position, and the point between the two merged cell contents is logically the "last edited" position, isn't it?

I very often find myself wanting to delete an empty line between two merged Markdown cells, which would be much easier if the cursor would already be there.

Additional context

When multiple cells are merged at once, there are of course multiple merge points.
It seems that there is already a notion of a "last selected cell in a selection" (at least there is a marker in the user interface), which AFAICT is always either at the very top or the very bottom of the selection.
If that's true, it would of course make most sense to put the cursor between the "last selected" cell and the rest of 'em.

When clicking with the mouse into a code cell, the cursor is set to the mouse position, this should of course be unchanged, even after merging two code cells.

Apparently, the cursor position is not stored in the notebook file, and after loading a notebook, all cursor positions seem to be set to the beginning of the cell. This is totally fine. I don't expect the cursor positions to be stored.

@mgeier
Copy link
Contributor Author

mgeier commented Jan 25, 2021

I've just discovered a logical extension of my proposal:

I was talking about merging cells, but one could also think about splitting cells.

When splitting a cell, the second one of the two new cells has its cursor at the beginning of the cell. This totally makes sense.

However, the cursor of the first cell is again reset to the beginning, while putting it at the end would be more consistent, because the end of the first cell was the "last edited" position.

I think my original suggestion about merging is more important, but why not make splitting also consistent?

@jasongrout
Copy link
Contributor

FYI, the cursor position is totally managed by CodeMirror - as far as I know we do nothing about it. It happens to be saved in the edit cell because we maintain the CodeMirror editor. The cases where you see the cursor reset to the beginning is likely just because we create a new codemirror.

I agree we could definitely do more to make the cursor management more sensible. Thanks for thinking through what sensible cursor management would look like!

@jasongrout jasongrout added this to the Future milestone Jan 25, 2021
@jasongrout
Copy link
Contributor

If you want to work on this, I think it probably would be fairly straightforward, though there may need to be some api additions to manage the cursor position, maybe?

@mgeier
Copy link
Contributor Author

mgeier commented Jan 28, 2021

I'm sorry, but I really don't have the capacity to work on this right now. Also, I'm not very good at JavaScript and I don't want to become good either (because I hate it).

I was hoping there are some other volunteers! Anyone?

Is there some tag or something to make this more visible to potential contributors?

In the meantime, I've found another situation with a minor quirk that could be improved:
When changing a cell from code to Markdown (and I guess in other directions as well), the cursor is also reset to the beginning.
I don't see a reason why it shouldn't stay at its previous position.

@jasongrout
Copy link
Contributor

I'm sorry, but I really don't have the capacity to work on this right now. Also, I'm not very good at JavaScript and I don't want to become good either (because I hate it).

I understand and empathize with you on each of these points :).

Is there some tag or something to make this more visible to potential contributors?

If we could point out where in the codebase someone could start trying to make these changes (and presuming we already have the api to move the cursor), I think this would be a "good first issue"

When changing a cell from code to Markdown (and I guess in other directions as well), the cursor is also reset to the beginning.
I don't see a reason why it shouldn't stay at its previous position.

Again, it's probably because we are replacing the cell with a different type of cell, and that probably involves creating a new CodeMirror, and the default is to start with the cursor at the top of the codemirror.

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

No branches or pull requests

2 participants