Commit 61951b16 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Use fewer event handlers

Instead of attaching an event handler to every line in the code view,
attach it only to the container and find the lineNumber based on the event
target element.

Notry: true
Change-Id: I1920f7a200cf2f5ffaf259c0aaa04d6fb6698d2d
Bug: v8:7327
Reviewed-on: https://chromium-review.googlesource.com/c/1346110
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57670}
parent 9bcb5eb5
......@@ -182,8 +182,16 @@ export class CodeView extends View {
console.log(e);
}
view.divNode.onclick = function (e) {
view.selectionHandler.clear();
view.divNode.onclick = function (e: MouseEvent) {
if (e.target instanceof Element && e.target.tagName == "DIV") {
const targetDiv = e.target as HTMLDivElement;
if (targetDiv.classList.contains("line-number")) {
e.stopPropagation();
view.onSelectLine(Number(targetDiv.dataset.lineNumber), !e.shiftKey);
}
} else {
view.selectionHandler.clear();
}
}
const base: number = source.startPosition;
......@@ -256,10 +264,6 @@ export class CodeView extends View {
lineNumberElement.classList.add("line-number");
lineNumberElement.dataset.lineNumber = lineNumber;
lineNumberElement.innerText = lineNumber;
lineNumberElement.onclick = function (e) {
e.stopPropagation();
view.onSelectLine(lineNumber, !e.shiftKey);
}
lineElement.insertBefore(lineNumberElement, lineElement.firstChild)
// Don't add lines to source positions of not in backwardsCompatibility mode.
if (this.source.backwardsCompatibility === true) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment