Skip to content

Commit 60f9aa7

Browse files
author
Chris K
committed
Highlight a range of a JS file.
1 parent 994f621 commit 60f9aa7

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/ecma-debugger/js-source-view.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ cls.JsSourceView = function(id, name, container_class)
7575

7676
templates.line_nummer = function()
7777
{
78-
return ['li',
79-
['input'],
80-
['span', 'handler', 'set-break-point'],
81-
];
78+
return (
79+
["li",
80+
["input"],
81+
["span", "handler", "set-break-point", "class", "break-point"]]);
8282
}
8383

8484
var updateLineNumbers = function(fromLine)
@@ -450,16 +450,27 @@ cls.JsSourceView = function(id, name, container_class)
450450
}
451451
}
452452

453-
this.show_and_flash_line = function(script_id, line_no)
453+
this.show_and_flash_line = function(script_id, line_no_start, line_no_end)
454454
{
455-
this.showLine(script_id, line_no);
456-
var line = this.get_line_element(line_no);
457-
if (line && typeof line_no == "number")
455+
if (typeof line_no_start != "number")
456+
return;
457+
458+
line_no_end || (line_no_end = line_no_start);
459+
this.showLine(script_id, line_no_start);
460+
this._change_highlight_class_lines("addClass", line_no_start, line_no_end);
461+
var cb = this._change_highlight_class_lines.bind(this, "removeClass",
462+
line_no_start, line_no_end);
463+
setTimeout(cb, 1000);
464+
};
465+
466+
this._change_highlight_class_lines = function(method, start, end)
467+
{
468+
for (var i = start, line; i <= end; i++)
458469
{
459-
line.addClass('selected-js-source-line');
460-
setTimeout(function(){line.removeClass('selected-js-source-line')}, 800);
470+
if (line = this.get_line_element(i))
471+
line[method]("selected-js-source-line");
461472
}
462-
}
473+
};
463474

464475
this.get_line_element = function(line_no)
465476
{
@@ -1002,12 +1013,12 @@ cls.JsSourceView = function(id, name, container_class)
10021013
cls.JsSourceView.update_breakpoints = function(script, line_numbers, top_line)
10031014
{
10041015
var BP_IMAGE_LINE_HEIGHT = 24;
1005-
var lines = line_numbers && line_numbers.querySelectorAll("span");
1016+
var lines = line_numbers && line_numbers.querySelectorAll(".break-point");
10061017
var bp_states = script && script.breakpoint_states;
10071018
if (typeof top_line != "number")
10081019
{
1009-
var input = line_numbers.querySelector("input");
1010-
top_line = input && Number(input.value);
1020+
var span = line_numbers.querySelector(".line-number");
1021+
top_line = span && Number(span.textContent);
10111022
}
10121023
if (lines && bp_states && typeof top_line == "number")
10131024
{

src/repl/repl_view.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,18 +927,21 @@ cls.ReplView = function(id, name, container_class, html, default_handler) {
927927

928928
this._handle_repl_show_log_entry_source_bound = function(event, target)
929929
{
930-
var line = parseInt(target.getAttribute("data-scriptline"));
931-
var script = parseInt(target.getAttribute("data-scriptid"));
930+
if (window.Tooltips)
931+
window.Tooltips.hide_tooltip();
932+
933+
var script_id = Number(target.getAttribute("data-scriptid"));
934+
var start_line = Number(target.getAttribute("data-scriptline"));
935+
var end_line = Number(target.getAttribute("data-script-endline"));
932936
var sourceview = window.views.js_source;
933937

934938
// This will also be set from show_and_flash_line, but setting it before showing
935939
// the view prevents the old script from flashing.
936-
window.runtimes.setSelectedScript(script);
940+
window.runtimes.setSelectedScript(script_id);
937941
UI.get_instance().show_view("js_mode");
938942
if (sourceview)
939-
{
940-
sourceview.show_and_flash_line(script, line);
941-
}
943+
sourceview.show_and_flash_line(script_id, start_line, end_line);
944+
942945
}.bind(this);
943946

944947
this.mode_labels = {

0 commit comments

Comments
 (0)