Make sure we don't initialize orgmode multiple times

pull/1/head
yflory 4 years ago
parent 1bd6c134ae
commit c747a36910

@ -123,7 +123,10 @@ define([
}; };
}); });
var init = false;
CodeMirror.registerHelper("orgmode", "init", function (editor) { CodeMirror.registerHelper("orgmode", "init", function (editor) {
if (init) { return; }
editor.setOption("extraKeys", { editor.setOption("extraKeys", {
"Tab": function(cm) { org_cycle(cm); }, "Tab": function(cm) { org_cycle(cm); },
"Shift-Tab": function(cm){ org_shifttab(cm); }, "Shift-Tab": function(cm){ org_shifttab(cm); },
@ -139,6 +142,7 @@ define([
"Shift-Right": function(cm){ org_shiftright(cm); } "Shift-Right": function(cm){ org_shiftright(cm); }
}); });
init = true;
editor.on('mousedown', toggleHandler); editor.on('mousedown', toggleHandler);
editor.on('touchstart', toggleHandler); editor.on('touchstart', toggleHandler);
editor.on('gutterClick', foldLine); editor.on('gutterClick', foldLine);
@ -155,6 +159,9 @@ define([
}); });
CodeMirror.registerHelper("orgmode", "destroy", function (editor) { CodeMirror.registerHelper("orgmode", "destroy", function (editor) {
if (!init) { return; }
init = false;
editor.off('mousedown', toggleHandler); editor.off('mousedown', toggleHandler);
editor.off('touchstart', toggleHandler); editor.off('touchstart', toggleHandler);
editor.off('gutterClick', foldLine); editor.off('gutterClick', foldLine);

Loading…
Cancel
Save