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

Empty cells of of an empty .dib notebook are deleted with first save #2803

Open
2 of 17 tasks
marckruzik opened this issue Mar 7, 2023 · 16 comments
Open
2 of 17 tasks

Comments

@marckruzik
Copy link
Contributor

marckruzik commented Mar 7, 2023

Describe the bug

  • create an empty .dib C# Notebook
  • the Notebook is created with a first empty cell
  • add another empty cell by clicking on the "+ Code"
  • the Notebook has 2 empty cells
  • save the Notebook using CTRL+S
  • the Notebook is reloaded in the same tab
  • the Notebook has only 1 cell

Screenshots

If applicable, add screenshots to help explain your problem.

empty_cell

Please complete the following:

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ):
EDIT 2023-03-09: I installed the last version of the polyglot notebook extension and VS Code, the problem still occurs.
Version: 1.0.415202+b72e199d0d854bd532a8103ce626a5aab4a71c07

  • OS
    • Windows 11
    • Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • Chrome
    • Edge
    • Firefox
    • Safari
  • Frontend
    • Jupyter Notebook
    • Jupyter Lab
    • nteract
    • Visual Studio Code
    • Visual Studio Code Insiders
    • Visual Studio
    • Other (please specify)
@colombod
Copy link
Member

colombod commented Mar 7, 2023

This happens because the dub format merges consecutive blocks with the same language

@marckruzik
Copy link
Contributor Author

marckruzik commented Mar 8, 2023

Ok, I understand the intended behavior.

During my work, I saw empty cells staying in the notebook, so I was thinking the .dib notebooks were able to save empty cells.
But I guess it's some kind of cache bug.
I made some tests, and I can actually reproduce a bug.

I create a Notebook with a cell containing a simple C# code, then:

  • I add 2 empty cells at the bottom
  • I save the Notebook
  • I close the Notebook
  • I open the Notebook
  • the 2 empty cells have disappeared
  • I do all the above again (re-adding 2 empty cells at the bottom, etc)

Then the bug happens, and empty cells stay.

Here is an example where I open a Notebook I modified following the above procedure several times. Please notice it contains empty cells when I open it.
Then I add and remove empty cells and save the notebook (CTRL+S). The right part (Notepad++) displays the content of the file.
Gif:
empty_cell_remaining

So here, I reached a point where:

  • I can see empty cells right when I open the file
  • I can put empty cells anywhere
  • the empty cells are not removed when closing and opening the file
  • the content of the file is correct (code modified is changed, no empty cell, no character returns or other things)

It looks like VS Code keeps in memory the empty cells.
Closing and reopening VS Code make the empty cells go away.

@marckruzik
Copy link
Contributor Author

I installed the last version of the polyglot notebook extension and VS Code, the problem still occurs.
(first post edited to put the last version number)

@colombod
Copy link
Member

With dib files it is by design. What is the scenario you are trying to implement with empty cells? Ipynb would support that .

@marckruzik
Copy link
Contributor Author

marckruzik commented Mar 10, 2023 via email

@colombod
Copy link
Member

But with dib is by design, it is not a bug, but worth some decent documentation to explain the file format and the implications

@marckruzik
Copy link
Contributor Author

Yes, I understand the intended behavior is to delete empty cells. So I would like empty cells to be deleted everytime.
But as I explained earlier, empty cells stay in cache:
#2803 (comment)
So I think those remaining empty cells are a bug and they should be removed.

@marckruzik
Copy link
Contributor Author

What should I do?
Keeping this issue as "please add more documentation about dib behavior with empty cells", and create another issue for "empty cells are kept in cache instead of being removed"?

@colombod
Copy link
Member

I am not sure I understand what you mean. Opening an issue to document file format sounds a good idea to me. the second part of your suggestion less clear. Dib will collapse empty fragment by design, I am not clear what is the scenario that needs to create a set of empty code cells all for the same kernel and persist them. What will the user do with that dib file?

@marckruzik
Copy link
Contributor Author

Opening an issue to document file format sounds a good idea to me.

I agree.

Dib will collapse empty fragment by design

I agree.

I am not sure I understand what you mean

There is some kind of bug cache, because sometimes when I open a notebook, there are empty cells. This is a bug.

Here is a shorter version of the gif from #2803 (comment) where I open the notebook, and we can see empty cells.

ezgif-5-2e6abb2c95

When I open a .dib notebook, there should be no empty cells, right?

Here is a shorter description of the bug:

  • The first few times I save and close a notebook with empty cells, at the next opening the empty cells disappear -> this is ok.
  • Then the bug happens, and empty cells stay at each opening (even when closing and reopening the notebook) -> this is a bug.

@colombod
Copy link
Member

Have you opened , linked this in the vscode repository? we do not control that part of api.

@colombod
Copy link
Member

@rebornix do you have any suggestion?

@marckruzik
Copy link
Contributor Author

Have you opened , linked this in the vscode repository? we do not control that part of api.

I did not open another issue. I use VS Code only for notebooks, therefore I post my issues here.

@jonsequitur
Copy link
Contributor

@marckruzik Setting aside the cache/display issue for a moment, which would you say is preferable?

  • Empty cells are removed on save and reopen
  • Empty cells are preserved on save and reopen
  • No preference

@jonsequitur
Copy link
Contributor

Dib will collapse empty fragment by design, I am not clear what is the scenario that needs to create a set of empty code cells all for the same kernel and persist them.

I think this is more of an emergent behavior than by design. It's the way the code happens to work, but the decision wasn't discussed heavily, and I can certainly see it as being unintuitive.

@marckruzik
Copy link
Contributor Author

marckruzik commented Mar 10, 2023

The interface allows to create empty cells, and to configure them.
So I would say:

  • Empty cells are preserved on save and reopen

I am going to explain the kind of situation which confused me.

Example:

  • There is a .dib notebook with 1 C# cell.
  • I open the notebook.
  • I put an empty cell at the end of the file, and set it as markdown, because I intend to write some explanation.
  • The notebook is marked as edited.
  • I save my work.
  • I close the notebook
  • I reopen the notebook
  • My last cell (the empty markdown cell) has disappeared.
  • I am confused, as I edited the notebook, see it as edited, and saved it.

Other confusion:

  • a cell is considered empty when it contains character returns -> it disappears
  • a cell is not considered empty when it contains a space -> it stays

I say this, because when working with markdown (and copy-paste), it's easy to leave a character return or a space. So I was not understanding why the empty cells were disappearing sometimes (and sometimes not).

Other confusion:

Conclusion

  1. From a user point of view, the most logical behavior would be for empty cells to be preserved on save and reopen.
  2. From a user point of view, deleting empty cells is closer to a "cleaning operation", which should happen only with an action (like an option menu), or with a warning at the time of automatic cleaning with immediate visual feedback.

I can add that I don't know any code or word editing software which actually deletes your empty lines or empty paragraphs, moreover without warning you. So I think the polyglot extension should preserve empty cells.

@jonsequitur jonsequitur added the bug Something isn't working label Mar 10, 2023
@jonsequitur jonsequitur changed the title Empty cells of of an empty notebook are deleted with first save Empty cells of of an empty .dib notebook are deleted with first save Mar 6, 2025
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

3 participants