From 3fd4343cfd86ef3e4271416056eecb4936feadfd Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 27 Nov 2017 01:33:16 +0300 Subject: [PATCH] usercss: don't recalc widget height => spend 0 time in CM 300ms -> 100ms rendering time in updateInvisible() for "RU AdList CSS Fixes" style --- edit/applies-to-line-widget.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/edit/applies-to-line-widget.js b/edit/applies-to-line-widget.js index 36dbf8cb..1a0482e9 100644 --- a/edit/applies-to-line-widget.js +++ b/edit/applies-to-line-widget.js @@ -169,6 +169,7 @@ function createAppliesToLineWidget(cm) { function *createWidgets(start, end, removed) { let i = 0; + let itemHeight; for (const section of findAppliesTo(start, end)) { while (removed[i] && removed[i].line.lineNo() < section.pos.line) { clearWidget(removed[i++]); @@ -182,7 +183,9 @@ function createAppliesToLineWidget(cm) { }); removed[i].section = section; const newNode = buildElement(section); - removed[i].node.parentNode.replaceChild(newNode, removed[i].node); + if (removed[i].node.parentNode) { + removed[i].node.parentNode.replaceChild(newNode, removed[i].node); + } removed[i].node = newNode; removed[i].changed(); yield removed[i]; @@ -193,9 +196,11 @@ function createAppliesToLineWidget(cm) { const widget = cm.addLineWidget(section.pos.line, buildElement(section), { coverGutter: true, noHScroll: true, - above: true + above: true, + height: itemHeight ? section.applies.length * itemHeight : undefined, }); widget.section = section; + itemHeight = itemHeight || widget.node.offsetHeight; yield widget; } removed.slice(i).forEach(clearWidget);