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

JN 7 → Code Folding starts at the first line regardless the type #6987

Closed
MichalRIcar opened this issue Jul 28, 2023 · 21 comments · Fixed by #7392
Closed

JN 7 → Code Folding starts at the first line regardless the type #6987

MichalRIcar opened this issue Jul 28, 2023 · 21 comments · Fixed by #7392

Comments

@MichalRIcar
Copy link

MichalRIcar commented Jul 28, 2023

Hi,

Jupyter Notebook 7:

I would like to propose to be able to fold any cell by the first line of text regardless its type.

Reasoning of it is that in many scenarios we have a cell with certain description and funcionality in some type of representation, flow.

Once user of a Notebook reads instructions, it is not necessary to keep the whole cell unfolded, actually it is very beneficial to allow to fold the whole cell keeping only the first row (likely a Title of a cell).

E.g. cell worthy to read and then fold it to see only a title "The Generator X"
Cell:

# The Generator X
# This function produces...
A = FunctionX()

# Callable Output
#...

Best,
Michal

@MichalRIcar MichalRIcar added enhancement status:Needs Triage Applied to issues that need triage labels Jul 28, 2023
@RRosio
Copy link
Collaborator

RRosio commented Aug 1, 2023

Thank you @MichalRIcar for submitting this issue! As we use CodeMirror for code folding, this might be either a change to configuration or an improvement to CodeMirror.

@RRosio RRosio removed the status:Needs Triage Applied to issues that need triage label Aug 1, 2023
@RRosio RRosio added this to the 7.0.x milestone Aug 1, 2023
@krassowski
Copy link
Member

The way I read it, this basically requests what was already implemented in jupyterlab/jupyterlab#14141

Screenshot from 2023-08-01 17-45-39

@MichalRIcar is this correct?

@MichalRIcar
Copy link
Author

Hi,

I will use an example from JN 6 with this feature on via codefolding extension:

Before Folding
image

After Folding
image

@MichalRIcar
Copy link
Author

As we can see, the "old" codefolding allowed to fold any cell by its first line regardless of its type..very useful feature in notebook presentation.

@krassowski
Copy link
Member

Sorry but I still do not see how it differs from what was implemented in jupyterlab/jupyterlab#14141.

@MichalRIcar
Copy link
Author

MichalRIcar commented Sep 7, 2023

@krassowski, thank you for pointing this out. You are absolutely correct that these two options are almost identical. However, I can only access the cell collapsing feature through the 'View' menu by selecting 'Collapse Selected Code' or 'Collapse All Code.' Perhaps I'm just missing some optional feature in Jupyter Notebook 7 because I don't see any dynamic option inside a cell to fold a whole code cell - similarly as we see in the example above?

Or idea behind this feature in JN7 is to not provide code folding in a code cell and rather forcing a user to use View option given by dev reasons? Originally (intuitively), I though it will be among these..
image

@krassowski
Copy link
Member

You can click on the blue bar next to the cell:

click-clock

This is somewhat documented in JupyterLab user guide but not in notebook itself. I think we should move the Notebook content User Guide to this repo (recreating videos using playwright) and then just embed it in JupyterLab docs.

@MichalRIcar
Copy link
Author

Right! That was the first thing I tried and it doesn't work even though I have code folding allowed everywhere in Settings..

@MichalRIcar
Copy link
Author

Is this dynamic bar folding connected with some other setup in the JN Settings?

@krassowski
Copy link
Member

Can you provide a recording and check if there are any errors in the JS console?

@MichalRIcar
Copy link
Author

MichalRIcar commented Sep 7, 2023

Absolutely, I've just checked that in JL it works indeed..but JN no luck. I've also checked that JN is not given by a browser - both Chrome and Edge behave same - i.e. no bar code folding behavior.

@MichalRIcar
Copy link
Author

MichalRIcar commented Sep 7, 2023

JS concole has these errors and tons of warnings
image

@MichalRIcar
Copy link
Author

Warnings
image

@MichalRIcar
Copy link
Author

2023-09-07.14-08-14.mp4

@jtpio
Copy link
Member

jtpio commented Sep 7, 2023

The collapsing issue might be similar to the one reported in #7020

@tmatsuzawa
Copy link

This active code folding is broken on my machine. I just installed the latest jupyter notebook.

@krassowski
Copy link
Member

krassowski commented May 30, 2024

I tested this in Notebook 7.2.0 which was recently released and it works well

@MichalRIcar and @tmatsuzawa can you confirm that it works with Notebook 7.2?

Edit: I also see no errors in the console (there are some warnings though, but nothing warranting an action)

@MichalRIcar
Copy link
Author

Hello @krassowski, thank you for following up on this important feature!

Good news is that now I can fold the very first cell, however, any other cell is still static - the blue left bar doesn't allow folding, doesn't change color when I move mouse on it like the first cell.

I have tried it using Chrome and Edge and the behavior is identical.
In Edge (only) the first cell once folded shrinks to approx. half length aligned to the right leaving half space as background as picture shows
image

@krassowski
Copy link
Member

I can fold the very first cell, however, any other cell is still static

This is very helpful, I can reproduce this. This is a CSS problem - another element obstructs the collapser so that it cannot be clicked.

body[data-notebook='notebooks']
.jp-Notebook
.jp-Notebook-cell:not(:first-child)::after,
body[data-notebook='notebooks']
.jp-Notebook
.jp-Notebook-cell:not(:first-child)::before {
content: ' ';
height: 100%;
position: absolute;
top: 0;
width: 11px;
}

It looks like it was originally added in #6433, but I do not understand why because it does not seem to do anything other than preventing clicking on the cell collapsed. @trungleduc do you remember if this was intentional? If not, these lines can be removed to fix the issue.

@krassowski
Copy link
Member

If this was intentional then maybe it should be configurable.

@trungleduc
Copy link
Contributor

Sorry for my late reply, I missed the notification.

It looks like it was originally added in #6433, but I do not understand why because it does not seem to do anything other than preventing clicking on the cell collapsed. @trungleduc do you remember if this was intentional? If not, these lines can be removed to fix the issue.

IIRC at this time, it was quite hard to have the same shadow visual as the old notebook due to the structure of the cell widgets. So I need to add pseudo-elements to apply the shadow effect.

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

Successfully merging a pull request may close this issue.

6 participants