From 37e95b9898685c297f01b8857d0fcb4fb1bf2e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sun, 30 Jun 2024 17:14:53 +0200 Subject: [PATCH] Move line highlighting after render Fix #231 --- static/web.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/static/web.js b/static/web.js index 1c6a4c1..11a9151 100644 --- a/static/web.js +++ b/static/web.js @@ -369,17 +369,9 @@ * @return {void} */ function fetchSnippet(session, result, snippet_file_name, do_evaluate, evaluateButton) { + var line = null if (snippet_file_name.includes(':')) { - let [ snippet_file_name, line ] = snippet_file_name.split(':') - if (!Number.isNaN(+line)) { - editShowLine(line) - } else if (line.includes('-')) { - let [ startLine, endLine ] = line.split('-') - if (+startLine > +endLine) { - [ endLine, startLine ] = [ startLine, endLine ] - } - editShowRegion(startLine, 1, endLine, -1) - } + var [ snippet_file_name, line ] = snippet_file_name.split(':') } session.setValue("// Loading snippet: https://github.com/ponylang/pony-tutorial/blob/main/code-samples/" + snippet_file_name + " ..."); httpRequest("GET", "https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/" + snippet_file_name, null, 200, @@ -389,6 +381,18 @@ if (do_evaluate) { doEvaluate(); } + + if (line !== null) { + if (!Number.isNaN(+line)) { + editShowLine(line) + } else if (line.includes('-')) { + let [ startLine, endLine ] = line.split('-') + if (+startLine > +endLine) { + [ endLine, startLine ] = [ startLine, endLine ] + } + editShowRegion(startLine, 1, endLine, -1) + } + } }, function (status, response) { set_result(result, "
Failed to fetch snippet" +