简体   繁体   中英

Why does Hide all input fail to return back to full code cell in Jupyter notebook?

This problem can be repeated, and I just find another similar code that have the same problem.

Usage : copy following code, and insert before the first cell, then paste it into and run that cell, finally a button will show below, clicking it will toggle the new cell to show or hide, but with a problem that the line number cannot appear automatically when I want to show it from hidden state, unless I click the editing area, which fires some event to make it back to normal.

How to fix it and the same problem of Hide All Input extension?


    from IPython.core.display import display, HTML
    toggle_code_str = '''
    <form action="javascript:code_toggle()"><input type="submit" id="toggleButton" value="Toggle Code"></form>
    '''

    toggle_code_prepare_str = '''
        <script>
        function code_toggle() {
            if ($('div.cell.code_cell.rendered.selected div.input').css('display')!='none'){
                $('div.cell.code_cell.rendered.selected div.input').hide();
            } else {
                $('div.cell.code_cell.rendered.selected div.input').show();
            }
        }
        </script>

    '''

    display(HTML(toggle_code_prepare_str + toggle_code_str))

    def toggle_code():
        display(HTML(toggle_code_str))

Found solution

Add to _hide_input\\main.js_ this line: cell.element.trigger("click"); after cell.metadata.hide_input = ! cell.metadata.hide_input; cell.metadata.hide_input = ! cell.metadata.hide_input; and save the js file and reopen that page, then shift into rise mode, everything renders pretty when toggle hide or not!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM