summaryrefslogtreecommitdiff
path: root/js/codeq/editor.js
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-09-29 14:15:28 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-09-29 14:18:34 +0200
commitb2983855ea01fd04a8ba53099d2d5ee7ebed31f9 (patch)
treec516a2d30ebc954d9118922d5e7155016d32d06b /js/codeq/editor.js
parent22cb497f9ed19548e30a4c86dd99aaa91fd4b344 (diff)
Add a statusbar to the editor widget
Diffstat (limited to 'js/codeq/editor.js')
-rw-r--r--js/codeq/editor.js30
1 files changed, 30 insertions, 0 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;
+};