summaryrefslogtreecommitdiff
path: root/js/codeq
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq')
-rw-r--r--js/codeq/editor.js30
-rw-r--r--js/codeq/prolog.js4
-rw-r--r--js/codeq/python.js14
3 files changed, 35 insertions, 13 deletions
diff --git a/js/codeq/editor.js b/js/codeq/editor.js
new file mode 100644
index 0000000..e7d15f9
--- /dev/null
+++ b/js/codeq/editor.js
@@ -0,0 +1,30 @@
+codeq.makeEditor = function (elt, options) {
+ var statusBar = document.createElement("div"),
+ updateStatusBar = function (pos) {
+ statusBar.innerHTML = 'line ' + (pos.line+1) + ', column ' + (pos.ch+1);
+ },
+ editor;
+
+ options.cursorHeight = 0.85;
+ options.lineNumbers = true;
+ options.matchBrackets = true;
+ options.extraKeys = {
+ // replace tabs with spaces
+ Tab: function (cm) {
+ var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
+ cm.replaceSelection(spaces);
+ }
+ };
+ editor = CodeMirror(elt, options),
+
+ statusBar.className = 'editor-statusbar';
+ updateStatusBar({line: 0, ch: 0});
+
+ editor.addPanel(statusBar, {position: 'bottom'});
+ editor.on('cursorActivity', function (instance) {
+ var pos = instance.getDoc().getCursor();
+ updateStatusBar(pos);
+ });
+
+ return editor;
+};
diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js
index 640aa99..87ac353 100644
--- a/js/codeq/prolog.js
+++ b/js/codeq/prolog.js
@@ -259,7 +259,9 @@
jqEditor = jqCode.find('.code_editor'),
jqTerminal = jqConsole.find('.console'),
jqHints = jqInfo.find('.hints'),
- editor = CodeMirror(jqEditor[0], { cursorHeight: 0.85, lineNumbers: true, matchBrackets: true }),
+ editor = codeq.makeEditor(jqEditor[0], {
+ mode: 'prolog'
+ }),
activityHandler = makeActivityHandler(editor, problemDef.id),
terminal = makePrologTerminalHandler(jqTerminal, editor, problemDef.id, activityHandler),
hinter = codeq.makeHinter(jqHints, jqEditor, editor, 'prolog_hints', problemDef.hint, commonHints, problemDef.plan),
diff --git a/js/codeq/python.js b/js/codeq/python.js
index 4724982..e20fe06 100644
--- a/js/codeq/python.js
+++ b/js/codeq/python.js
@@ -217,19 +217,9 @@
jqEditor = jqCode.find('.code_editor'),
jqTerminal = jqConsole.find('.console'),
jqHints = jqInfo.find('.hints'),
- editor = CodeMirror(jqEditor[0], {
- cursorHeight: 0.85,
- lineNumbers: true,
- matchBrackets: true,
+ editor = codeq.makeEditor(jqEditor[0], {
mode: 'python',
- indentUnit: 4,
- extraKeys: {
- // replace tabs with spaces
- Tab: function (cm) {
- var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
- cm.replaceSelection(spaces);
- }
- }
+ indentUnit: 4
}),
activityHandler = makeActivityHandler(editor, problemDef.id),
terminal = makePythonTerminalHandler(jqTerminal, editor, problemDef.id, activityHandler),