Skip to content

Commit

Permalink
Close #8: click on error line number now focus or opens file where er…
Browse files Browse the repository at this point in the history
…ror occured
  • Loading branch information
Volodymyr Sergeyev committed Jan 23, 2013
1 parent 81f1e4b commit 0850cd0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ide/static/js/liveide-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@
if (!editor) return;

$.get("/file_run/", {path: editor.file.path}, function (data) {
data = data.replace(/(line\s[0-9](?=[,\s]))/gi, "<a href='#' class='liveide-line-number'>$1</a>");
data = data.replace(/([.\w+]*)[",\s]+(line\s[0-9](?=[,\s]))/gi,
'$1" <a href="#"" class="liveide-line-number" data-id="$1">$2</a>');
that.dom.console.append("<pre>" + data + "</pre>");
that.dom.console.find("pre:last")[0].scrollIntoView(true);
that.flash("Run complete");
Expand Down
32 changes: 28 additions & 4 deletions ide/static/js/liveide.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,36 @@
// Click in console on error line number
$(document).on("click", this.dom.line_number, function (e) {
e.preventDefault();
var line = $(this).text().replace("line ", ""),
ed = that.active.editor;
var id = $(this).data("id"),
line = parseInt($(this).text().replace("line ", "")),
ed = that.active.editor,
is_open = false;

if (ed) {
ed.editor.gotoLine(parseInt(line));
if (ed && ed.file.path.indexOf(id) > -1) { // Error in currently opened file
ed.editor.gotoLine(line);
ed.editor.focus();
} else {
$.each(that.editors, function (i, v) {
if (v.file && v.file.path.indexOf(id) > -1) {
is_open = true;
that.focus_editor(v.id);
that.active.editor.editor.gotoLine(line);
}
});

// Lookup in project files for source of error
if (!is_open)
$.each(that.active.project.files, function (k, file) {
if (file.path.indexOf(id) > -1) {
// Need to load file from FS and then open and focus
$.get("/file_content/", {path: file.path}, function (data) {
file.content = data;
that.add_editor(file, file.title, file.content);
that.focus_editor(file.id);
that.active.editor.editor.gotoLine(line);
});
}
});
}
});

Expand Down

0 comments on commit 0850cd0

Please sign in to comment.