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

Add configurable delay for initialization #1028

Merged
merged 2 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ Parameters:
description: Hotkey to fold/unfold code
input_type: hotkey
default: Alt-F
- name: init_delay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name used in the js is init_timeout!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

description: Add a delay before initializing the extension. Useful when the gutter is not being initialized correctly.
input_type: number
min: 0
default: 0
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ Link: readme.md
Icon: codefolding_editor.png
Main: edit.js
Compatibility: 4.x, 5.x
Parameters:
- name: init_delay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, the name used in the js is init_timeout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching. I somehow reverted the change I did to the JS file.

description: Add a delay before initializing the extension. Useful when the gutter is not being initialized correctly.
input_type: number
min: 0
default: 1000
Section: edit
17 changes: 11 additions & 6 deletions src/jupyter_contrib_nbextensions/nbextensions/codefolding/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ define([
// define default config parameter values
var params = {
codefolding_hotkey : 'Alt-f',
init_timeout : 1000
};

// updates default params with any specified in the provided config data
Expand Down Expand Up @@ -109,12 +110,12 @@ define([
}
/* User can click on gutter of unselected cells, so make sure we store metadata in the correct cell */
var cell = Jupyter.notebook.get_selected_cell();
if (cell.code_mirror != cm) {
if (cell.code_mirror !== cm) {
var cells = Jupyter.notebook.get_cells();
var ncells = Jupyter.notebook.ncells();
for (var k = 0; k < ncells; k++) {
var _cell = cells[k];
if (_cell.code_mirror == cm ) { cell = _cell; break; }
if (_cell.code_mirror === cm ) { cell = _cell; break; }
}
}
cell.metadata.code_folding = lines;
Expand All @@ -123,12 +124,12 @@ define([
/**
* Activate codefolding in CodeMirror options, don't overwrite other settings
*
* @param cell {codecell.CodeCell} code cell to activate folding gutter
* @param cm codemirror instance
*/
function activate_cm_folding (cm) {
var gutters = cm.getOption('gutters').slice();
if ( $.inArray("CodeMirror-foldgutter", gutters) < 0) {
gutters.push('CodeMirror-foldgutter')
gutters.push('CodeMirror-foldgutter');
cm.setOption('gutters', gutters);
}

Expand Down Expand Up @@ -242,7 +243,10 @@ define([
/* require our additional custom codefolding modes before initialising fully */
require(['./firstline-fold', './magic-fold'], function () {
if (Jupyter.notebook._fully_loaded) {
initExistingCells();
setTimeout(function () {
console.log('Codefolding: Wait for', params.init_timeout, 'ms');
initExistingCells();
}, params.init_timeout);
}
else {
events.one('notebook_loaded.Notebook', initExistingCells);
Expand All @@ -252,8 +256,9 @@ define([
else {
activate_cm_folding(Jupyter.editor.codemirror);
setTimeout(function () {
console.log('Codefolding: Wait for', params.init_timeout, 'ms');
Jupyter.editor.codemirror.refresh();
}, 1000);
}, params.init_timeout);
}
};

Expand Down