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

Fix dirty dots not preserved when moving multiple cells #16225

Merged
merged 7 commits into from
Apr 25, 2024

Conversation

Alanhou1222
Copy link
Contributor

@Alanhou1222 Alanhou1222 commented Apr 22, 2024

References

Fixes #16060
Closes #16161 (includes)

Code changes

In packages/cells/src/model.ts, make the setDirty() function into a set function set isDirty().
In packages/notebook/src/widget.ts, move logics that set new cells dirty into the for loop of the moveCell function and make the code more clear.

User-facing changes

dirty dots are kept even when moving multiple cells
image
image

Backwards-incompatible changes

None

Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@Alanhou1222
Copy link
Contributor Author

@krassowski Not sure if it's expected, but moved cells won't remember their content before being moved. Therefore, even if users revert the changes on a moved cell, the cell is still considered dirty.

@krassowski
Copy link
Member

but moved cells won't remember their content before being moved

Indeed, undo does not work after moving a cell - good catch! This is not expected, we should open a separate issue to track it and then fix it.

This PR looks good to me on the implementation side (the failing Python tests are unrelated); ideally we would also include unit tests in packages/notebook/test/widget.spec.ts for the dirty dot being preserved. Would you be interested in adding such a unit test (whether in this PR or in another)?

@Alanhou1222
Copy link
Contributor Author

but moved cells won't remember their content before being moved

Indeed, undo does not work after moving a cell - good catch! This is not expected, we should open a separate issue to track it and then fix it.

This PR looks good to me on the implementation side (the failing Python tests are unrelated); ideally we would also include unit tests in packages/notebook/test/widget.spec.ts for the dirty dot being preserved. Would you be interested in adding such a unit test (whether in this PR or in another)?

Sure, I'll write some unit tests.

@Alanhou1222
Copy link
Contributor Author

@krassowski I added two tests, one verifies dirty state is preserved after moving one code cell and another verifies dirty states are preserved after moving multiple cells. Let me know if you think there are other situations that should be tested.

@krassowski krassowski self-requested a review April 24, 2024 09:02
Comment on lines +433 to +436
if (this.widgets[to + i - n + 1].model.type === 'code') {
(this.widgets[to + i - n + 1].model as CodeCellModel).isDirty =
dirtyState[i];
}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why is it that rendered and headingCollapsed do not need - n + 1 but isDirty needs it? It seems a bit suspicious to me that the implementation here differs from the one for markdown cell properties. I suspect that one of those is wrong.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

Tested locally, works great. Thank you @Alanhou1222!

@krassowski krassowski merged commit d1120b5 into jupyterlab:main Apr 25, 2024
82 checks passed
gderocher pushed a commit to gderocher/jupyterlab that referenced this pull request Apr 26, 2024
…6225)

* fix dirty dot

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* reserves multiple cells' dirty dots when moved

* make dirtyState array and add from > to condition

* add tests to verify moveCell() preserves dirty state

---------

Co-authored-by: Kriti Gupta <kritigupta@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

Dirty dot goes away after moving a modified cell
3 participants