From 613445ae28e3390683b4a4e623b2bfd72cdef118 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 08:58:59 +0100 Subject: [PATCH 01/10] hyperlink compiler error line numbers an ugly but useful hack --- static/web.html | 9 +++++++++ static/web.js | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/static/web.html b/static/web.html index 3001781..947eb21 100644 --- a/static/web.html +++ b/static/web.html @@ -6,6 +6,15 @@ + diff --git a/static/web.js b/static/web.js index 637bac5..963c540 100644 --- a/static/web.js +++ b/static/web.js @@ -535,6 +535,10 @@ return "[" + code + "]"; }).replace(/run `rustc --explain (E\d\d\d\d)` to see a detailed explanation/g, function(text, code) { return "see the detailed explanation for " + code + ""; + }).replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, function(text, r1,c1, r2,c2) { + return "" + text + ""; + }).replace(/^<anon>:(\d+) /mg, function (text, r1) { + return "" + text + ""; }); } From ab0feb92b07e3f982382d1522e1b6f31659dfca4 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 20:43:03 +0100 Subject: [PATCH 02/10] move function edit* from HTML to web.js --- static/web.html | 9 --------- static/web.js | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/static/web.html b/static/web.html index 947eb21..3001781 100644 --- a/static/web.html +++ b/static/web.html @@ -6,15 +6,6 @@ - diff --git a/static/web.js b/static/web.js index 963c540..c40681d 100644 --- a/static/web.js +++ b/static/web.js @@ -695,3 +695,12 @@ }, false); }()); + + +// called via javascript:fn events from formatCompilerOutput +var old_range; +function editSel() { return window.ace.edit("editor").selection; } +function editRestore() { if (old_range) { editSel().setSelectionRange(old_range, false) } } +function editLine(r1) { var e = editSel(); e.clearSelection(); e.setSelectionAnchor(r1-1,0); e.selectLine() } +function editShow(r1,c1, r2,c2) { var e = editSel(); old_range = e.getRange(); e.clearSelection(); e.setSelectionAnchor(r1-1,c1-1); e.selectTo(r2-1,c2-1) } +function editGo(r1,c1) { var e = editSel(); e.moveCursorTo(r1-1,c1-1,false); old_range = undefined } From e8748c8a46ce772153fc92cd14b37a1f8f7e7ef1 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 20:45:18 +0100 Subject: [PATCH 03/10] reformat formatCompilerOutput attributes re-ordered, no other changes --- static/web.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/static/web.js b/static/web.js index c40681d..590247b 100644 --- a/static/web.js +++ b/static/web.js @@ -530,16 +530,29 @@ }); } + function jumpToLine(text, r1) { + return "" + text + ""; + } + + function jumpToRegion(text, r1,c1, r2,c2) { + return "" + text + ""; + } + function formatCompilerOutput(text) { - return ansi2html(text).replace(/\[(E\d\d\d\d)\]/g, function(text, code) { - return "[" + code + "]"; - }).replace(/run `rustc --explain (E\d\d\d\d)` to see a detailed explanation/g, function(text, code) { - return "see the detailed explanation for " + code + ""; - }).replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, function(text, r1,c1, r2,c2) { - return "" + text + ""; - }).replace(/^<anon>:(\d+) /mg, function (text, r1) { - return "" + text + ""; - }); + return ansi2html(text) + .replace(/\[(E\d\d\d\d)\]/g, + function(text, code) { + return "[" + code + "]"; + }) + .replace(/run `rustc --explain (E\d\d\d\d)` to see a detailed explanation/g, + function(text, code) { + return "see the detailed explanation for " + code + ""; + }) + .replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, jumpToRegion) + .replace(/^<anon>:(\d+) /mg, jumpToLine); } addEventListener("DOMContentLoaded", function() { From 7bf3e94524cf4a27a6770de9146f3f445a551eff Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 20:51:44 +0100 Subject: [PATCH 04/10] spread & re-order out the javascript: fns --- static/web.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/static/web.js b/static/web.js index 590247b..dd07e24 100644 --- a/static/web.js +++ b/static/web.js @@ -712,8 +712,34 @@ // called via javascript:fn events from formatCompilerOutput var old_range; -function editSel() { return window.ace.edit("editor").selection; } -function editRestore() { if (old_range) { editSel().setSelectionRange(old_range, false) } } -function editLine(r1) { var e = editSel(); e.clearSelection(); e.setSelectionAnchor(r1-1,0); e.selectLine() } -function editShow(r1,c1, r2,c2) { var e = editSel(); old_range = e.getRange(); e.clearSelection(); e.setSelectionAnchor(r1-1,c1-1); e.selectTo(r2-1,c2-1) } -function editGo(r1,c1) { var e = editSel(); e.moveCursorTo(r1-1,c1-1,false); old_range = undefined } + +function editSel() { + return window.ace.edit("editor").selection; +} + +function editGo(r1,c1) { + var e = editSel(); + e.moveCursorTo(r1-1,c1-1,false); + old_range = undefined; +} + +function editRestore() { + if (old_range) { + editSel().setSelectionRange(old_range, false); + } +} + +function editShow(r1,c1, r2,c2) { + var e = editSel(); + old_range = e.getRange(); + e.clearSelection(); + e.setSelectionAnchor(r1-1,c1-1); + e.selectTo(r2-1,c2-1); +} + +function editLine(r1) { + var e = editSel(); + e.clearSelection(); + e.setSelectionAnchor(r1-1,0); + e.selectLine(); +} From f318eb6254a5c66587dea6df21d78bc284ccf07c Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 21:57:36 +0100 Subject: [PATCH 05/10] mend the edit jumping line selection was broken click wasn't leaving focus in the editor --- static/web.js | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/static/web.js b/static/web.js index dd07e24..8f90501 100644 --- a/static/web.js +++ b/static/web.js @@ -531,12 +531,14 @@ } function jumpToLine(text, r1) { - return "" + text + ""; + return "" + text + ""; } function jumpToRegion(text, r1,c1, r2,c2) { - return "" + text + ""; } @@ -552,7 +554,7 @@ + ">detailed explanation for " + code + ""; }) .replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, jumpToRegion) - .replace(/^<anon>:(\d+) /mg, jumpToLine); + .replace(/^<anon>:(\d+)/mg, jumpToLine); } addEventListener("DOMContentLoaded", function() { @@ -713,33 +715,37 @@ // called via javascript:fn events from formatCompilerOutput var old_range; -function editSel() { - return window.ace.edit("editor").selection; +function editorGet() { + return window.ace.edit("editor"); } function editGo(r1,c1) { - var e = editSel(); - e.moveCursorTo(r1-1,c1-1,false); + var e = editorGet(); old_range = undefined; + e.focus(); + e.selection.clearSelection(); + e.selection.moveCursorTo(r1-1, c1-1, false); } function editRestore() { if (old_range) { - editSel().setSelectionRange(old_range, false); + editorGet().selection.setSelectionRange(old_range, false); } } -function editShow(r1,c1, r2,c2) { - var e = editSel(); - old_range = e.getRange(); - e.clearSelection(); - e.setSelectionAnchor(r1-1,c1-1); - e.selectTo(r2-1,c2-1); +function editShowRegion(r1,c1, r2,c2) { + var es = editorGet().selection; + old_range = es.getRange(); + es.clearSelection(); + es.setSelectionAnchor(r1-1, c1-1); + es.selectTo(r2-1, c2-1); } -function editLine(r1) { - var e = editSel(); - e.clearSelection(); - e.setSelectionAnchor(r1-1,0); - e.selectLine(); +function editShowLine(r1) { + var es = editorGet().selection; + old_range = es.getRange(); + es.clearSelection(); + es.moveCursorTo(r1-1, 0); + es.moveCursorLineEnd(); + es.selectTo(r1-1, 0); } From 68bb54bb29647fedf8fb3ca844f08f76a4d26d74 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 21:58:00 +0100 Subject: [PATCH 06/10] style the linejump text --- static/web.css | 6 ++++++ static/web.js | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/static/web.css b/static/web.css index 301686a..6358672 100644 --- a/static/web.css +++ b/static/web.css @@ -532,6 +532,12 @@ button[disabled]:last-child::before { border-bottom: 1px dashed rgba(0, 0, 0, 0.25); } +a.linejump { + cursor: pointer; + color: #97248D; + border-bottom: thin #97248D dotted; +} + .ace_dark .rustc-output { border-bottom-color: rgba(255, 255, 255, 0.25); } diff --git a/static/web.js b/static/web.js index 8f90501..43136d5 100644 --- a/static/web.js +++ b/static/web.js @@ -533,13 +533,15 @@ function jumpToLine(text, r1) { return "" + text + ""; + " onmouseout=\"javascript:editRestore()\"" + + " class=\"linejump\">" + text + ""; } function jumpToRegion(text, r1,c1, r2,c2) { return "" + text + ""; + " onmouseout=\"javascript:editRestore()\"" + + " class=\"linejump\">" + text + ""; } function formatCompilerOutput(text) { From ffa093ac7f03bfea959b2ec5b54445e0f2c778d4 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 22:20:14 +0100 Subject: [PATCH 07/10] linejump for panic!() --- static/web.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/web.js b/static/web.js index 43136d5..aaabceb 100644 --- a/static/web.js +++ b/static/web.js @@ -555,6 +555,7 @@ return "see the detailed explanation for " + code + ""; }) + .replace(/<anon>:(\d+)$/mg, jumpToLine) // panicked at 'foo', $& .replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, jumpToRegion) .replace(/^<anon>:(\d+)/mg, jumpToLine); } From 856ac95cbf13357d38e8b4ce57f5e3c266dc20c0 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Sat, 18 Jul 2015 12:55:21 +0100 Subject: [PATCH 08/10] fix \n+ static/web.js: line 556, col 30, Bad line breaking before '+'. --- static/web.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/web.js b/static/web.js index aaabceb..c7f2f71 100644 --- a/static/web.js +++ b/static/web.js @@ -552,8 +552,8 @@ }) .replace(/run `rustc --explain (E\d\d\d\d)` to see a detailed explanation/g, function(text, code) { - return "see the detailed explanation for " + code + ""; + return "see the detailed explanation for " + code + ""; }) .replace(/<anon>:(\d+)$/mg, jumpToLine) // panicked at 'foo', $& .replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, jumpToRegion) From 55524ef82a541f10e947b075d11700742fab0fd0 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Fri, 17 Jul 2015 21:33:18 +0100 Subject: [PATCH 09/10] prevent repeated warnings in console "Automatically scrolling cursor into view after selection change" "this will be disabled in the next version" "set editor.$blockScrolling = Infinity to disable this message" cf. https://github.com/ajaxorg/ace/issues/2499 > [...] I'm calling a documented API, and it's in turn > telling me to call an undocumented one. and https://github.com/angular-ui/ui-ace/issues/104 --- static/web.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/web.js b/static/web.js index c7f2f71..3c767e0 100644 --- a/static/web.js +++ b/static/web.js @@ -575,6 +575,7 @@ themes = document.getElementById("themes"); editor = ace.edit("editor"); set_result.editor = editor; + editor.$blockScrolling = Infinity; session = editor.getSession(); themelist = ace.require("ace/ext/themelist"); From ad45b1113d988335e3235f0a21cc6e62e828bdfc Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Sat, 18 Jul 2015 17:10:53 +0100 Subject: [PATCH 10/10] mend region-showing after blockScrolling fix $blockScrolling = Infinity breaks the auto-show of selection, fix with explicit scrolling improve restore of old region (the Ace docs I found are a bit sparse, so this is works-for-me-ware) --- static/web.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/static/web.js b/static/web.js index 3c767e0..b3f2a13 100644 --- a/static/web.js +++ b/static/web.js @@ -553,7 +553,7 @@ .replace(/run `rustc --explain (E\d\d\d\d)` to see a detailed explanation/g, function(text, code) { return "see the detailed explanation for " + code + ""; + ">detailed explanation for " + code + ""; }) .replace(/<anon>:(\d+)$/mg, jumpToLine) // panicked at 'foo', $& .replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, jumpToRegion) @@ -576,6 +576,7 @@ editor = ace.edit("editor"); set_result.editor = editor; editor.$blockScrolling = Infinity; + editor.setAnimatedScroll(true); session = editor.getSession(); themelist = ace.require("ace/ext/themelist"); @@ -728,27 +729,43 @@ function editGo(r1,c1) { old_range = undefined; e.focus(); e.selection.clearSelection(); + e.scrollToLine(r1-1, true, true); e.selection.moveCursorTo(r1-1, c1-1, false); } function editRestore() { if (old_range) { - editorGet().selection.setSelectionRange(old_range, false); + var e = editorGet(); + e.selection.setSelectionRange(old_range, false); + var mid = (e.getFirstVisibleRow() + e.getLastVisibleRow()) / 2; + var intmid = Math.round(mid); + var extra = (intmid - mid)*2 + 2; + var up = e.getFirstVisibleRow() - old_range.start.row + extra; + var down = old_range.end.row - e.getLastVisibleRow() + extra; + if (up > 0) { + e.scrollToLine(mid - up, true, true); + } else if (down > 0) { + e.scrollToLine(mid + down, true, true); + } // else visible enough } } function editShowRegion(r1,c1, r2,c2) { - var es = editorGet().selection; + var e = editorGet(); + var es = e.selection; old_range = es.getRange(); es.clearSelection(); + e.scrollToLine(Math.round((r1 + r2) / 2), true, true); es.setSelectionAnchor(r1-1, c1-1); es.selectTo(r2-1, c2-1); } function editShowLine(r1) { - var es = editorGet().selection; + var e = editorGet(); + var es = e.selection; old_range = es.getRange(); es.clearSelection(); + e.scrollToLine(r1, true, true); es.moveCursorTo(r1-1, 0); es.moveCursorLineEnd(); es.selectTo(r1-1, 0);