From 8fe3934c6e37caa09506567055224a0fc5944feb Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sun, 27 Jan 2013 09:59:19 -0600 Subject: [PATCH] fixed codemirror syntax highlighting, thanks Mariano --- VERSION | 2 +- applications/admin/controllers/default.py | 3 ++- applications/admin/static/js/ajax_editor.js | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 4d5d468d..b167470f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.1-alpha.2+timestamp.2013.01.27.09.45.36 +Version 2.4.1-alpha.2+timestamp.2013.01.27.09.58.34 diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index caeb5d83..019b25d0 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -645,6 +645,7 @@ def edit(): code = request.vars.data.rstrip().replace('\r\n', '\n') + '\n' compile(code, path, "exec", _ast.PyCF_ONLY_AST) except Exception, e: + # offset calculation is only used for textarea (start/stop) start = sum([len(line) + 1 for l, line in enumerate(request.vars.data.split("\n")) if l < e.lineno - 1]) @@ -654,7 +655,7 @@ def edit(): else: offset = 0 highlight = {'start': start, 'end': start + - offset + 1, 'lineno': e.lineno} + offset + 1, 'lineno': e.lineno, 'offset': offset} try: ex_name = e.__class__.__name__ except: diff --git a/applications/admin/static/js/ajax_editor.js b/applications/admin/static/js/ajax_editor.js index 44d5de7d..d2d733ee 100644 --- a/applications/admin/static/js/ajax_editor.js +++ b/applications/admin/static/js/ajax_editor.js @@ -43,8 +43,9 @@ function doHighlight(highlight) { if (window.ace_editor) { window.ace_editor.gotoLine(highlight.lineno); } else if (window.mirror) { - window.mirror.setSelection({line:highlight.lineno,ch:0}, - {line:highlight.end,ch:0}); + // Put the cursor at the offending line: + window.mirror.setCursor({line:highlight.lineno-1, + ch:highlight.offset+1}); } else if (window.eamy) { // not implemented } else if (window.textarea) {