-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Persist code cell collapsed #3981
Persist code cell collapsed #3981
Conversation
@ellisonbg Let me know if this is implemented how you envisioned. I don't find it particularly intuitive to have to run As far as I understand it, this supports the case where two people have the same file open at once in different JupterLab instances and want to have different things collapsed. However, if this isn't a case we want to support, than just having the collapsed state part of the model makes more sense. |
Things we talked about today in the meeting:
|
Is there anything else at the moment that should also be saved here? Here are a couple of options I was thinking for the label:
Or, if we want to keep it collapsed state specific atm
/cc @afshin |
Yeah, this is going to be tough to name. Of the options you list, I am
probably partial to:
* Save Notebook with View State
The "Save Notebook..." follows our current menu design and both "view" and
"current view" don't quite capture it. Or we could go more generic:
* Save Notebook
* Save Notebook with Extras
...Naming...
…On Wed, Mar 7, 2018 at 1:57 PM, Saul Shanabrook ***@***.***> wrote:
Add a new extension point and keyboard shortcut (command+shift+S) that
extensions can do additional things with before saving (such as persist
this state).
Is there anything else at the moment that should also be saved here? Does
"Save with View" make sense as a label?
Couple of options for label:
- Save with View
- Save with Current View
- Save with View State
Or, if we want to keep it collapsed state specific atm
- Save Notebook with Collapsed State
- Save Notebook with Collapsed/Revealed
/cc @afshin <https://github.com/afshin>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3981 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABr0NaGrLZIJg7jEQ1Ht8aoDAY68ir1ks5tcFe5gaJpZM4SRKZF>
.
--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgranger@calpoly.edu and ellisonbg@gmail.com
|
I am glad to see the menu extension system getting some use! Looks like it needs a rebase, but the overall implementation looks sound to me. My main question is this: will this functionality be widely-used enough that Put another way, I think there is value to having the cell model be reasonably close to that described in nbformat. |
@ian-r-rose thanks for looking over this.
Yeah it took my like ten looking over my code to figure out what it was doing, so it should be changed somehow. Also, I don't why I added that indirection. I will try rebasing and removing that and hopefully that will be clearer and still work properly. |
8a91e83
to
2cec23b
Compare
@ellisonbg Coming back to this, I wonder if the notebook specific save should be 'Save Notebook with Collapsed State' instead of 'Save Notebook with View State'. Otherwise, the user will not really know what is part of the view state. If we extend the command in the future to do more, we could update the name to be more general. @ian-r-rose I removed the extra abstraction, should be more readable now. |
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.
Just took this for a spin, and it works really nicely. Am I right in thinking that "collapsed"
is a semi-official metadata field for this behavior? In the current UI both inputs and outputs are able to be collapsed, but this only applies to outputs, so I found the naming to be a touch confusing. I don't think it's a big problem, though.
persistAndSave: (current: NotebookPanel) => { | ||
NotebookActions.persistOutputsCollapsed(current.notebook); | ||
app.commands.execute('docmanager:save'); | ||
return Promise.resolve(); |
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.
Is there a reason you are returning a resolved promise here, rather than return app.comands.execute('docmanager:save');
?
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.
Nope. I have changed it.
packages/notebook/src/actions.tsx
Outdated
*/ | ||
export | ||
function persistOutputsCollapsed(widget: Notebook): void { | ||
if (!widget.model || !widget.activeCell) { |
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.
Do we need an active cell check here? As far as I know, we should always have one, but it doesn't seem strictly necessary for the functionality.
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.
Nope I don't believe we do, I was just copy and pasting. Removed.
"default": { }, | ||
"properties": { | ||
"command": { "default": "filemenu:persist-and-save" }, | ||
"keys": { "default": ["Accel Shift S"] }, |
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.
This now conflicts with the "Save As..." shortcut (sorry, I know your PR predates that!). There is a lot of precedence for "Save As..." having Accel Shift S
as a shortcut. Can we choose something else?
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 changed to Accel Ctrl S
which works for me on mac/chrome.
NotebookActions.persistOutputsCollapsed(widget); | ||
for (const cell of widget.widgets) { | ||
if (cell instanceof CodeCell) { | ||
expect(cell.model.initiallyCollapsed).to.be(cell.outputHidden); |
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.
This looks like it needs to be fixed.
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.
Yep. Changed to use metadata.
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.
Thanks! This looks good to me, pending CI. If we want to change the label to "Collapsed State"
, that's cool too.
Does the classic notebook collapse the whole cell, or just the outputs? Edit: looks to me like just the outputs. In which case, I think you have the correct behavior (even if the naming is a bit confusing). |
There's a separate EDIT: also a separate |
As far as I can tell, |
Looks like So I guess I should update the PR to use EDIT: Does that seem like the right approach? |
Thanks for the link @akhmerov. I don't see a difference in how the classic notebook handles |
AFAIR the classic notebook indeed never made use of these fields. |
I found the official reference: https://github.com/jupyter/nbformat/blob/master/docs/changelog.rst#44 |
In that case, I see a couple of options:
Thoughts? |
Should |
I agree that it's older, but I was hoping to avoid breaking existing notebooks, and it is in the schema. Can you elaborate on what the different use is? Again, I could not see what it did other than hide the outputs. |
I was perhaps too hasty. I base my evaluation on the issue discussion found by @saulshanabrook (the nbformat docs are also not very helpful BTW). The discussion suggests that collapsed is perhaps more like "visible but occupying very little space". The current jupyterlab UI does not have an alternative means of showing such state, instead only implementing something more similar to output hiding. Based on the above I believe that:
|
@akhmerov Thanks for the suggestions.
Do you think enabling scrolling for outputs covers this use case? Since it limits how much vertical space the outputs take up? |
To be honest, I'm not an ultimate nbformat authority, and the docs are not too specific. Let's try to see WWCND (what would classic notebook do). So it seems it is would be more in line with the classic notebook to unify |
bf028ec
to
6ce4241
Compare
I rebased and updated the |
Great, thanks for all the back and forth! |
Does nbconvert respect folded cells? That is when we export the notebook to an HTML, will folded cells in the notebook be folded in the HTML? |
@dclong quoting the changelog of nbformat:
If I remember correctly though, modifying nbconvert config to use these fields should be relatively straightforward. |
This pull request has been mentioned on Jupyter Community Forum. There might be relevant details there: https://discourse.jupyter.org/t/hiding-code-cell-on-launch/1763/4 |
This adds support for loading the collapsed state of a code cell output from the
collapsed
metadata property, as well as saving to that property when thepersistOutputsCollapsed
command is run.We do this by just storing the persisted value of the collapsed state in the
CodeCellModel
. The view initializes itself from this value, but when it is updated (you collapse a cell) it doesn't update the model. Only when the command is explicitly run does it set the metadata value in the model, which is then saved to disk when it is serialized to JSON.This addresses the collapsed output cells part of #3799 but doesn't work on persisting the input cells.