From 3a23c4edb349e453752159e1a775a4e5e4e719db Mon Sep 17 00:00:00 2001 From: Josh Barnes Date: Thu, 18 Feb 2016 17:20:35 +0000 Subject: [PATCH] bugfix in `nbextensions/usability/codefolding` - fix dependency race condition with a require call. --- .../usability/codefolding/firstline-fold.js | 6 +++--- nbextensions/usability/codefolding/main.js | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nbextensions/usability/codefolding/firstline-fold.js b/nbextensions/usability/codefolding/firstline-fold.js index f64b875..b274edc 100644 --- a/nbextensions/usability/codefolding/firstline-fold.js +++ b/nbextensions/usability/codefolding/firstline-fold.js @@ -5,10 +5,10 @@ CodeMirror.registerHelper("fold", "firstline", function(cm, start) { var lineText = cm.getLine(start.line); var found = lineText.lastIndexOf(Token,0); if (found == 0) { - end = cm.lastLine(); + end = cm.lastLine(); return {from: CodeMirror.Pos(start.line, null), - to: CodeMirror.Pos(end, null)}; + to: CodeMirror.Pos(end, null)}; } } - return ; + return ; }); diff --git a/nbextensions/usability/codefolding/main.js b/nbextensions/usability/codefolding/main.js index 1b82e89..200a7a9 100644 --- a/nbextensions/usability/codefolding/main.js +++ b/nbextensions/usability/codefolding/main.js @@ -118,10 +118,10 @@ define([ var found = jQuery.inArray("CodeMirror-foldgutter", gutters); if ( found == -1) { cell.code_mirror.setOption('gutters', [ gutters , "CodeMirror-foldgutter"]); - } + } } } - + /** * Add codefolding gutter to a new cell * @@ -162,7 +162,7 @@ define([ break; } cell.code_mirror.refresh(); - } + } } cell.code_mirror.on('fold',updateMetadata); cell.code_mirror.on('unfold',updateMetadata); @@ -183,19 +183,19 @@ define([ link.rel = "stylesheet"; link.href = require.toUrl(name, 'css'); document.getElementsByTagName("head")[0].appendChild(link); - }; + }; /** * Initialize extension * */ - var load_extension = function() { + var load_extension = function() { load_css('codemirror/addon/fold/foldgutter.css'); /* change default gutter width */ load_css( './foldgutter.css'); - /* additional custom codefolding mode */ - require(['./firstline-fold']); - setTimeout(initGutter, 100) + /* require our additional custom codefolding modes before initialising + fully */ + require(['./firstline-fold', './magic-fold'], initGutter); }; return {load_ipython_extension : load_extension};