-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
for more information, see https://pre-commit.ci
…FixDirtyDot merge
Thanks for making a pull request to jupyterlab! |
@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. |
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 |
Sure, I'll write some unit tests. |
@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. |
if (this.widgets[to + i - n + 1].model.type === 'code') { | ||
(this.widgets[to + i - n + 1].model as CodeCellModel).isDirty = | ||
dirtyState[i]; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
…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>
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](https://private-user-images.githubusercontent.com/44051348/324624252-2400ea4d-1f1f-4956-aa68-39a76df4280a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE4NTA4MTIsIm5iZiI6MTcyMTg1MDUxMiwicGF0aCI6Ii80NDA1MTM0OC8zMjQ2MjQyNTItMjQwMGVhNGQtMWYxZi00OTU2LWFhNjgtMzlhNzZkZjQyODBhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI0VDE5NDgzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI3MzY5NjE2NTBlMDJlOTc3ZDRkMTgwNTQzNzM1NTYwYzA4NmMxMDdkZmNkNWQ3NWFkZTI5NmUzOTI1NjJjNjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.cbq116xKHATbKzNAoMm0C1OTOFey6Di0x3r7f7xmWkg)
![image](https://private-user-images.githubusercontent.com/44051348/324624274-1ab9bff8-8e8c-4f90-bef5-947d557e5d4c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE4NTA4MTIsIm5iZiI6MTcyMTg1MDUxMiwicGF0aCI6Ii80NDA1MTM0OC8zMjQ2MjQyNzQtMWFiOWJmZjgtOGU4Yy00ZjkwLWJlZjUtOTQ3ZDU1N2U1ZDRjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI0VDE5NDgzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA0ZDNiZjM1MGE5MjNhODVjOTM0ZGU5MDYxNGQwYjgxYTlhYmViNjYzNmQwMzQ4OWIyNzM4M2NiNGI2MWJmYzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wDEOSUhyNtNQgnVMCdzFdd0JwmnMGj-7KOlyQjlOykc)
Backwards-incompatible changes
None