Skip to content

Commit a598153

Browse files
author
minjk-bl
committed
CHROME: added codemirror ipython mode and some missing codes
1 parent c154b51 commit a598153

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

js/com/component/PopupComponent.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@
1212
//============================================================================
1313
// [CLASS] PopupComponent
1414
//============================================================================
15+
// CHROME: notebook/js/codemirror-ipython
16+
(function(mod) {
17+
if (typeof exports == "object" && typeof module == "object"){ // CommonJS
18+
mod(requirejs("codemirror/lib/codemirror"),
19+
requirejs("codemirror/mode/python/python")
20+
);
21+
} else if (typeof define == "function" && define.amd){ // AMD
22+
define('notebook/js/codemirror-ipython',["codemirror/lib/codemirror",
23+
"codemirror/mode/python/python"], mod);
24+
} else {// Plain browser env
25+
mod(CodeMirror);
26+
}
27+
})(function(CodeMirror) {
28+
"use strict";
29+
30+
CodeMirror.defineMode("ipython", function(conf, parserConf) {
31+
var pythonConf = {};
32+
for (var prop in parserConf) {
33+
if (parserConf.hasOwnProperty(prop)) {
34+
pythonConf[prop] = parserConf[prop];
35+
}
36+
}
37+
pythonConf.name = 'python';
38+
pythonConf.singleOperators = new RegExp("^[\\+\\-\\*/%&|@\\^~<>!\\?]");
39+
if (pythonConf.version === 3) {
40+
pythonConf.identifiers = new RegExp("^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*");
41+
} else if (pythonConf.version === 2) {
42+
pythonConf.identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
43+
}
44+
return CodeMirror.getMode(conf, pythonConf);
45+
}, 'python');
46+
47+
CodeMirror.defineMIME("text/x-ipython", "ipython");
48+
});
49+
1550
define([
1651
'text!vp_base/html/component/popupComponent.html!strip',
1752
'css!vp_base/css/component/popupComponent',
@@ -25,9 +60,9 @@ define([
2560
/** codemirror */
2661
'codemirror/lib/codemirror',
2762
'codemirror/mode/python/python',
28-
'notebook/js/codemirror-ipython',
2963
'codemirror/addon/display/placeholder',
30-
'codemirror/addon/display/autorefresh'
64+
'codemirror/addon/display/autorefresh',
65+
'notebook/js/codemirror-ipython'
3166
], function(popupComponentHtml, popupComponentCss
3267
, com_util, com_Const, com_String, com_interface, Component, DataSelector, codemirror
3368
) {

js/loadVisualpython.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//============================================================================
1313
// Load Visual Python
1414
//============================================================================
15+
// CHROME: removed code
16+
define([
1517
// CHROME: removed .css extension type
1618
'css!vp_base/css/root',
1719
'vp_base/js/com/com_Const',
@@ -27,7 +29,7 @@
2729
//========================================================================
2830
// Define variable
2931
//========================================================================
30-
var Jupyter;
32+
var Jupyter = null;
3133
var events;
3234
var liveNotebook = false;
3335

@@ -149,7 +151,9 @@
149151
/**
150152
* visualpython config util
151153
*/
152-
window.vpConfig = new com_Config();
154+
// CHROME: added extType as 'chrome'
155+
// window.vpConfig = new com_Config();
156+
window.vpConfig = new com_Config('chrome');
153157
window.VP_MODE_TYPE = com_Config.MODE_TYPE;
154158
/**
155159
* visualpython kernel
@@ -236,7 +240,10 @@
236240
let cfg = readConfig();
237241

238242
vpConfig.readKernelFunction();
239-
_addToolBarVpButton();
243+
// CHROME: edited
244+
if (Jupyter) {
245+
_addToolBarVpButton();
246+
}
240247
_loadVpResource(cfg);
241248
_checkVersion();
242249

0 commit comments

Comments
 (0)